I have been detecting NFC enabled card in my app to read tag value. Following is my code
OnCreate()
nfcAdapter = NfcAdapter.getDefaultAdapter(AuthDriverCard.this);
piTap = PendingIntent.getActivity(
this, TAP_REQUEST_CODE, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), PendingIntent.FLAG_UPDATE_CURRENT);
IntentFilter tagDetected = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndefDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter techDetected = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
nfcIntentFilter = new IntentFilter[]{techDetected, tagDetected, ndefDetected};
OnResume
if (nfcAdapter != null) {
nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
}
OnPause
if (nfcAdapter != null) {
nfcAdapter.enableForegroundDispatch(AuthDriverCard.this, piTap, nfcIntentFilter, null);
}
OnNewIntent()
protected void onNewIntent(Intent intent) {
// my logic here
}
This code works fine almost every time. But some time card is not detecting
and i found that OnNewIntent() is not firing
.
What could be the problem. Do i need to set intent filter in manifest
also ? I haven't set it in manifest so far but it worked for me without any problem. Is there any problem in my java code ?
Please suggest
NOTE - Restart(after killing app) app solve the problem. card detection works after that.