当读取一个NDEF标记它表现出与QUOT的内容; NFC服务"代替该应用表现出、标记、内容、NDEF

2023-09-05 04:51:01 作者:一辈子不换的好 值得用一辈子的

我想读我使​​用ADT的Andr​​oid应用程序中的一个NDEF标签。

I'm trying to read a NDEF tag from my app in Android using ADT.

C时的$ C $是完全一样的一个在本的教程

The code it's exactly the same as the one found in this tutorial.

它的正确显示的内容,但是,而不是打开我的应用程序,它显示在我的应用程序(相同的用户界面),这就是所谓的NFC服务与蓝牙图标的克隆。

The content it's showed correctly but, instead of opening my app, it's showed in a clone of my app (same UI) that it's called "NFC service" with a bluetooth icon.

现在的问题是:如果我已经打开应用程序,然后,在阅读之后,克隆自己和我所做的一切后,阅读它的NFC服务克隆完成

The problem is: if I already opened the app then, after the reading, it clone itself and everything I do after the reading it's done on the "NFC service" clone.

这是多任务菜单显示:

,其中SERVIZIO NFC翻译,如说,NFC服务

where "Servizio NFC" translate, as said, in "NFC service"

推荐答案

我不能在这个问题上,该应用程序是显示为NFC服务,在历史上的蓝牙图标评论

I can't comment on the issue that the app is shown as "NFC service" with a Bluetooth icon in the history -- that obviously looks like a bug.

不过,如果你希望你的应用程序,以获得NFC事件,而这已经是在前台,我强烈建议使用前景派遣或阅读器模式API (读卡器模式是新的Andr​​oid 4.4系统)。

However, if you want your app to receive NFC events while it already is in the foreground, I strongly recommend to use the foreground dispatch or the reader mode API (reader mode is new in Android 4.4).

为了使用前景派遣,您将创建一个悬而未决的意图是这样的:

In order to use the foreground dispatch, you would create a pending intent like this:

PendingIntent pendingIntent = PendingIntent.getActivity(
    this,
    0,
    new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),
    0);

然后,在你活动的 onResume()方法,你可以使前景调度是这样的:

Then, in your activity's onResume() method, you would enable the foreground dispatch like this:

NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
nfcAdapter.enableForegroundDispatch(this, pendingIntent, null, null);

请注意,您可以定义意图过滤器或标签技术列表并将其传递给 enableForegroundDispatch()方法,如果您不希望您的活动获得的每发现标记。

Note, that you could define intent filters or tag technology lists and pass them to the enableForegroundDispatch() method if you don't want your activity to receive every discovered tag.

您将收到意图通过活动的 onNewIntent()办法通知你有关发现标签:

You will then receive intents notifying you about discovered tags through the activity's onNewIntent() method:

public void onNewIntent(Intent intent) {
    ...
}

请记住,您必须停用前景派遣您的活动的的onPause()方法:

Remember that you have to disable the foreground dispatch in your activity's onPause() method:

NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);
nfcAdapter.disableForegroundDispatch(this);