Code example for NfcAdapter

Methods: setNdefPushMessageCallback, setOnNdefPushCompleteCallback

0
 
        void onNfcPush(); 
        NdefMessage onGetNfcMessage();
    } 
    public NfcWrapper(NfcAdapter nfcAdapter, NfcWrapper.onNfcPushListener onNfcPushListener, Activity activity) {
        nfcAdapter.setNdefPushMessageCallback(onCreateMessage, activity);
        nfcAdapter.setOnNdefPushCompleteCallback(onNdefPushCompleteCallback, activity);
        this.onNfcPushListener = onNfcPushListener;
    } 
 
    private NfcAdapter.CreateNdefMessageCallback onCreateMessage = new NfcAdapter.CreateNdefMessageCallback() {
        @Override 
        public NdefMessage createNdefMessage(NfcEvent nfcEvent) { 
            return onNfcPushListener.onGetNfcMessage(); 
        } 
    }; 
 
    private NfcAdapter.OnNdefPushCompleteCallback onNdefPushCompleteCallback = new NfcAdapter.OnNdefPushCompleteCallback() {
        @Override 
        public void onNdefPushComplete(NfcEvent nfcEvent) { 
            onNfcPushListener.onNfcPush();