I am attempting to create an application centered around NFC paired with multiple RFIDs. For this reason I am programming the RFIDs with NDefRecords that open a specific activity in my application. The NdefMessage doing this is as follows
NdefRecord mimeRecord =
NdefRecord.createMime("application/com.example.rfidprogrammer.testactivity","Some text".getBytes(StandardCharsets.US_ASCII));
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[] { mimeRecord});
And my manifest for the activity I am opening uses the following intent filter:
<activity
android:name=".TestClass"
android:exported="true">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType =
"application/com.example.rfidprogrammer.testactivity"/>
</intent-filter>
</activity>
The code that is writing to the RFID I am using looks like this:
private String writeTagData(Tag tag) {
StringBuilder sb = new StringBuilder();
//get takes given tag and creates a Ndef based on information
Ndef ndef = Ndef.get(tag);
if(ndef != null){
try {
ndef.connect();
ndef.writeNdefMessage(ndefMessage);
ndef.close();
} catch (IOException | FormatException e) {
e.printStackTrace();
}
}else{
//if the Ndef failed NdefFormatable will attempt, if this fails the rfid device is not
// recognized by this device
NdefFormatable formatable = NdefFormatable.get(tag);
try {
formatable.connect();
formatable.format(ndefMessage);
formatable.close();
} catch (IOException | FormatException e) {
e.printStackTrace();
}
}
byte[] id = tag.getId();
sb.append("\tID (hex): ").append(toHex(id)).append('\n');
sb.append("\tID (reversed hex): ").append(toReversedHex(id)).append('\n');
sb.append("\tID (dec): ").append(toDec(id)).append('\n');
sb.append("\tID (reversed dec): ").append(toReversedDec(id)).append('\n');
Log.v("Write MODE\n",sb.toString());
return sb.toString();
}
I am successfully writing this to the tag as when I then attempt to scan the RFID I am taken to the correct activity but if my application is already open, a different version of my application with a different logo is shown in the recent apps section. Is there a way for me to use Mimetypes, NdefRecords, and NFC to open the desired activity in the version of the application currently running? Can this be done without having to account/process for the intent to open a specific activity in your application?