I have tried to implement the code from Google documentation but it is still not clear for me. What am I missing here?
This is method in MainActivity.java:
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction())) {
Parcelable[] rawMessages =
intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
if (rawMessages != null) {
NdefMessage[] messages = new NdefMessage[rawMessages.length];
for (int i = 0; i < rawMessages.length; i++) {
messages[i] = (NdefMessage) rawMessages[i];
Log.i("nfcccc",messages[i].toString());
}
// Process the messages array.
Log.i("from tag: ",messages.toString());
Toast.makeText(this,messages.toString(),Toast.LENGTH_LONG).show();
}
}
}
In onCreated method I have also initialized nfcAdapter:
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
In manifest file I have this:
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
I spent couple of days trying to implement that, but it is still not working. What I am doing is that I use NFC Tools android app to save plain text and the I want to read this data in my own app>