我正在实施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()命令全屏显示。 –