Example usage for android.nfc NfcAdapter isNdefPushEnabled

List of usage examples for android.nfc NfcAdapter isNdefPushEnabled

Introduction

In this page you can find the example usage for android.nfc NfcAdapter isNdefPushEnabled.

Prototype

@java.lang.Deprecated

public boolean isNdefPushEnabled() 

Source Link

Document

Return true if the NDEF Push (Android Beam) feature is enabled.

Usage

From source file:com.brq.wallet.activity.receive.ReceiveCoinsActivity.java

@TargetApi(16)
protected void shareByNfc() {
    if (Build.VERSION.SDK_INT < 16) {
        // the function isNdefPushEnabled is only available for SdkVersion >= 16
        // We would be theoretically able to push the message over Ndef, but it is not
        // possible to check if Ndef/NFC is available or not - so dont try it at all, if
        // SdkVersion is too low
        return;//from  w ww .jav  a 2s . co m
    }

    NfcAdapter nfc = NfcAdapter.getDefaultAdapter(this);
    if (nfc != null && nfc.isNdefPushEnabled()) {
        nfc.setNdefPushMessageCallback(new NfcAdapter.CreateNdefMessageCallback() {
            @Override
            public NdefMessage createNdefMessage(NfcEvent event) {
                NdefRecord uriRecord = NdefRecord.createUri(getPaymentUri());
                return new NdefMessage(new NdefRecord[] { uriRecord });
            }
        }, this);
        ivNfc.setVisibility(View.VISIBLE);
        ivNfc.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Utils.showSimpleMessageDialog(ReceiveCoinsActivity.this,
                        getString(R.string.nfc_payment_request_hint));
            }
        });
    } else {
        ivNfc.setVisibility(View.GONE);
    }
}