Context: Framework 4.5, Xamarin.Android v5.0
I want to use NFC technology to implement shortcuts for application users. I want users to scan the NFC tag, so I just need to put the value in a predefined schema.
I put some arguments in my NFC message, and I do this when I write the message in my NFC tag:
var tag = intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
var ndef = Ndef.Get(tag);
NdefRecord external = NdefRecord.CreateExternal(applicationPackageName(), "letypetype", Encoding.ASCII.GetBytes("param"));
NdefRecord appRecord = NdefRecord.CreateApplicationRecord(applicationPackageName());
NdefMessage ndefMessage = new NdefMessage(external, appRecord);
if (ndef != null)
{
ndef.Connect();
ndef.WriteNdefMessage(ndefMessage);
}
Then I want to use it in my application, so I put it in AndroidManifest.xml:
<uses-feature android:name="android.hardware.nfc" android:required="true" />
And in my main activity I have the following filter of intentions:
[IntentFilter(new[] { NfcAdapter.ActionNdefDiscovered },
Categories = new[] { Intent.CategoryDefault },
DataScheme = "vnd.android.nfc", DataPathPrefix = "letypetype",
DataHost = "ext")]
public class Activity1 : Activity
{ ...
And I'm trying to process my parameter in this action using the override OnResume method:
protected override void OnResume()
{
base.OnResume();
if (NfcAdapter.ActionNdefDiscovered.Equals(this.Intent.Action))
{
IParcelable[] rawMsgs = this.Intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages);
if (rawMsgs != null)
{
NdefMessage[] msgs = new NdefMessage[rawMsgs.Length];
for (int i = 0; i < rawMsgs.Length; i++)
{
msgs[i] = (NdefMessage)rawMsgs[i];
}
}
}
}
But there is no way to return it. Therefore, I am sure that something is wrong, but I do not know what.