NFC空标签读取问题 [英] NFC Empty tag reading issue

查看:1792
本文介绍了NFC空标签读取问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在参与一个项目,我需要使用NFC进行通信我。

I am currently involved in a project in which I need to communicate using NFC.

当我试图读取NFC标签,它完美地工作URI和文字。

When I'm trying to read an NFC tag, its perfectly working for URI and texts.

但是,当我试图读取一个空的NFC标签显示其默认这是不是我的code定义的空标签的消息。

But when I'm trying to read an empty NFC tag its showing a default "Empty tag" message which is not defined in my code.

的Andr​​oidManifest.xml 的:

<activity
  android:name=".ReadActivity"
  android:label="@string/app_name" >
  <intent-filter>
    <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
    <data android:mimeType="application/example.nfcdemo"/>   
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter>  
  <intent-filter>
    <action android:name="android.nfc.action.TAG_DISCOVERED"/>
    <category android:name="android.intent.category.DEFAULT"/>
  </intent-filter> 
</activity>

的onCreate()方法:

if (intent.getType() != null && intent.getType().equals(MimeType.NFC_DEMO)) {
  Parcelable[] rawMsgs = getIntent().getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
  NdefMessage msg = (NdefMessage) rawMsgs[0];
  NdefRecord cardRecord = msg.getRecords()[0];
  String msg = new String(cardRecord.getPayload());
  displayMessage("Tag Written here : " +msg);
}
else {
  displayMessage("This is an empty tag");
}

我想表现出这样的自定义消息用我自己的活动。

I would like to show a custom message like this using my own activity.

有什么建议?

推荐答案

您可能要启用前台调度。这样,你的活动可以接收所有NFC意图,包括空标签的。请参阅<一href="http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch" rel="nofollow">http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch有关说明和示例。

You probably want to enable foreground dispatching. That way your activity can receive all NFC intents, including ones from empty tags. See http://developer.android.com/guide/topics/connectivity/nfc/advanced-nfc.html#foreground-dispatch for instructions and example.

这篇关于NFC空标签读取问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆