When I compile/build my app, it creates my APK without any errors. Additionally, in Android Studio, I don't have error notifications. So I expect the app to work. However, when I install and open the app, as soon as I scan an NFC tag, I get the error message "Unfortunately BMT_Admin has stopped working".
The only thing I'm trying to do is write an external record to the tag, called "payload", and then also write an AAR (Android Application Record) to the tag that can be called by future scans. The code that I'm using follows:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.hasExtra(NfcAdapter.EXTRA_TAG))
{
Toast.makeText(this, "NFC Scan", Toast.LENGTH_SHORT).show();
Tag tag = intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
byte[] payload = "my string_tag1".getBytes();
NdefRecord[] ndefRecords = new NdefRecord[0];
ndefRecords[0] = NdefRecord.createExternal("nfctutorials", "externaltype", payload);
ndefRecords[1] = NdefRecord.createApplicationRecord("com.example.myapp");
NdefMessage ndefMessage = new NdefMessage(ndefRecords);
writeNdefMessage(tag, ndefMessage);
}
}
I'm assuming there is something I'm doing here that isn't correct and is throwing an error when I try to scan a tag. But I have no idea what that could be.