Skip to content Skip to sidebar Skip to footer

Onnewintent Not Called After Tapping To Another Nfc Enabled Device

I'm coding in c# with Xamarin. I tried to share data over NFC from one device to another. Open browser -> Options -> Share -> App4 to MainActivity Both of my devices are r

Solution 1:

Yes, you are missing something: You registered the foreground dispatch to listen for NDEF messages of the type "text/plain", which means you either expect a Text record or a record with the MIME type text/plain.

ndefDetected = new IntentFilter(NfcAdapter.ActionNdefDiscovered);
ndefDetected.AddDataType("text/plain");
ndefDetected.AddCategory(Intent.CategoryDefault);
intentF = new IntentFilter[] { ndefDetected };
manager.DefaultAdapter.EnableForegroundDispatch(this, mPendingIntent, intentF, null);

However, your app pushes an absolute URI record with an invalid (empty!) type name.

NdefRecord record = new NdefRecord(NdefRecord.TnfAbsoluteUri,newbyte[0], newbyte[0], System.Text.Encoding.Default.GetBytes(share));
manager.DefaultAdapter.EnableForegroundNdefPush(this, new NdefMessage(record));

In order to match the intent filter, you would need to push a Text record instead:

byte[] text = System.Text.Encoding.UTF8.GetBytes(share);
byte[] language = System.Text.Encoding.ASCII.GetBytes("en");
byte[] payload = newbyte[1 + language.Count + text.Count];
payload[0] = (byte)language.Count;
System.Array.Copy(language, 0, payload, 1, language.Count);
System.Array.Copy(text, 0, payload, 1 + language.Count, text.Count);
NdefRecord record = new NdefRecord(NdefRecord.TnfWellKnown, new List<byte>(NdefRecord.RtdText).ToArray(), newbyte[0], payload);
manager.DefaultAdapter.EnableForegroundNdefPush(this, new NdefMessage(record));

Post a Comment for "Onnewintent Not Called After Tapping To Another Nfc Enabled Device"