我正在實施NFC到Xamarin Forms現有的應用程序,最初是爲Zebra TC51(android 6.0)。Xamarin nfc固定的應用程序
應用程序必須固定,以便用戶無法訪問設備的其餘部分。
在OnCreate中,內MainActivity.cs,我有以下行:
NfcManager NfcManager = (NfcManager)Android.App.Application.Context.GetSystemService(Context.NfcService);
_nfcAdapter = NfcManager.DefaultAdapter;
然後我用下面的類來接收標籤:
[Activity IntentFilter(new[] { "android.nfc.action.NDEF_DISCOVERED" },
DataMimeType = MainActivity.ViewApeMimeType,
Categories = new[] { "android.intent.category.DEFAULT" })]
public class NfcActivity : Activity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
//SetContentView(Resource.Layout.DisplayHominid);
if (Intent == null)
{
return;
}
var intentType = Intent.Type ?? String.Empty;
if (MainActivity.ViewApeMimeType.Equals(intentType))
{
var rawMessages = Intent.GetParcelableArrayExtra(NfcAdapter.ExtraNdefMessages);
var tag = Intent.GetParcelableExtra(NfcAdapter.ExtraTag) as Tag;
var id = System.Text.Encoding.Default.GetString(tag.GetId());
var msg = (NdefMessage)rawMessages[0];
var tagMessage = msg.GetRecords()[0];
var content = Encoding.ASCII.GetString(tagMessage.GetPayload());
// Call another function with Tag ID and contents here
}
}
}
此代碼檢索標籤ID和內容,但僅限於該應用程序未固定。如果該應用是固定的,則無法顯示NFC服務窗口,並忽略該標籤。
任何人都可以提出一個解決方法。由於激烈的限制,我不想使用NFCforms NUGET軟件包。
TIA。 Pete
你是什麼意思的「應用程序被固定」? –
它使用StartLockTask()命令全屏顯示。 –