I am trying to use NFC to send a URL from an Android app to other phone, both have enabled NFC and working fine.
when i tried to test the app nothing happen,
i have tried the following app from store and it work perfectly: https://play.google.com/store/apps/details?id=com.maxsoft.ndeftagemulator
this is my code:
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if (nfcAdapter == null) {
Toast.makeText(this, "NFC not supported on this device.", Toast.LENGTH_LONG).show();
finish();
return;
}
nfcAdapter.setNdefPushMessageCallback(event -> {
String url = "https://www.example.com";
NdefRecord ndefRecord = NdefRecord.createUri(url);
NdefMessage ndefMessage = new NdefMessage(ndefRecord);
return ndefMessage;
}, this);
nfcAdapter.setOnNdefPushCompleteCallback(event -> Toast.makeText(MainActivity.this, "URL sent via NFC.", Toast.LENGTH_LONG).show(), this);
i also added permission in Manifest
<uses-permission android:name="android.permission.NFC" />
i searched for answers here and checked the following with no success ( android API +29 )
Sending URL from Android to Windows Phone via NFC gives Play Store link