android.nfc.NfcAdapter.ReaderCallback Java Examples

The following examples show how to use android.nfc.NfcAdapter.ReaderCallback. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NfcActivityManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public void enableReaderMode(Activity activity, ReaderCallback callback, int flags,
        Bundle extras) {
    boolean isResumed;
    Binder token;
    synchronized (NfcActivityManager.this) {
        NfcActivityState state = getActivityState(activity);
        state.readerCallback = callback;
        state.readerModeFlags = flags;
        state.readerModeExtras = extras;
        token = state.token;
        isResumed = state.resumed;
    }
    if (isResumed) {
        setReaderMode(token, flags, extras);
    }
}
 
Example #2
Source File: NfcActivityManager.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Override
public void onTagDiscovered(Tag tag) throws RemoteException {
    NfcAdapter.ReaderCallback callback;
    synchronized (NfcActivityManager.this) {
        NfcActivityState state = findResumedActivityState();
        if (state == null) return;

        callback = state.readerCallback;
    }

    // Make callback without lock
    if (callback != null) {
        callback.onTagDiscovered(tag);
    }

}
 
Example #3
Source File: NfcManager.java    From nfcspy with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint("NewApi")
private void setReaderMode(boolean enable, int delay) {
	if (nfcAdapter == null || !hasHCE())
		return;

	if (!enable) {
		nfcAdapter.disableReaderMode(activity);
		return;
	}

	Bundle opts = new Bundle();
	opts.putInt(NfcAdapter.EXTRA_READER_PRESENCE_CHECK_DELAY, 5000);

	int flags = NfcAdapter.FLAG_READER_SKIP_NDEF_CHECK;
	flags |= NfcAdapter.FLAG_READER_NFC_A;

	// For the 'READ BINARY' problem of Braodcom's NFC stack.
	// Only works on Android 4.4+
	nfcAdapter.enableReaderMode(activity, new ReaderCallback() {

		@Override
		public void onTagDiscovered(Tag tag) {
			Intent i = new Intent().putExtra(EXTRA_TAG, tag);
			tagListener.onNewTagIntent(i);
		}
	}, flags, opts);
}