I have a class, which creates conncection to NFC and two activites. Both of them creates an object of that class so they can connect to NFC. Earlier it worked somehow but now I've got problem - my application doesn't do anything onNewIntent, even on the first activity. Instead of it, I can see "New tag collected" from build-in app called "Tags" (Nexus S).
What should I do?
class:
public NFCForegroundUtil(Activity activity)
{
super();
this.activity = activity;
mAdapter = NfcAdapter.getDefaultAdapter(activity
.getApplicationContext());
mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
activity, activity.getClass())
.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);
try
{
ndef2.addDataType("*/*");
}
catch (MalformedMimeTypeException e)
{
throw new RuntimeException("fail", e);
}
mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };
mTechLists = new String[][] { new String[] {
// android.nfc.tech.NfcV.class.getName(),
android.nfc.tech.NfcA.class.getName(),
android.nfc.tech.IsoDep.class.getName() } };
mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);
}
activity 1:
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
nfcForegroundUtil = new NFCForegroundUtil(this);
}
@Override
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
Intent i = new Intent(this, NfcDisplayLabelActivity2.class);
startActivity(i);
}
I was seeing "New tag collected" from build-in app called "Tags" because my application didn't work properly.
When it works ok, it has higher priority than "Tags" and phone reads tags from my application. But when it works unproperly and phone collect a tag, "Tags" application is activated and "Tags" application talks to my device.
After repairing code, my app has higher priority and phone reads tags using my application.