2017-04-24 143 views
0

我正在实施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

+0

你是什么意思的“应用程序被固定”? –

+0

它使用StartLockTask()命令全屏显示。 –

回答

0

鉴于您希望让应用程序在像场景(限制用户访问设备)的自助服务终端模式下运行,更好的选择可能是使用Zebra's Enterprise Home Screen
通过这种方式,您可以锁定设备,限制对通知的访问,禁用键盘锁等等(如果需要)。而且您仍然可以添加对用户有用的其他应用。

在EHS的配置中,您可以指定自动启动您的应用,以便在设备启动时立即启动。

如果您只需要您的应用程序,比屏幕固定更好的解决方案可能会安装设备策略控制器,并使用已在棉花糖for the COSU (Corporate Owned - Single Use) devices中引入的taskLockMode。

如果仍然有问题,您可以尝试询问Zebra's developer forum的问题。

声明:我为Zebra Technologies工作。

+0

谢谢pfmaggi, 是的,我可以使用企业主屏幕或SOTI(正如我们以前使用的那样,因为它是跨平台的,因此更易于维护)。 但我真正需要的是摆脱丑陋的黑色NFC服务屏幕出现,每当我读标签。这看起来会更好,并能解决问题。 你能建议如何做到这一点? –