[新增标签收集"而不是阅读应用标签 - NFC的Andr​​oid [英] "New Tag Collected" instead of reading tags of application - NFC android

查看:165
本文介绍了[新增标签收集"而不是阅读应用标签 - NFC的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类,它创建conncection到NFC和两个activites。他们都将创建该类的对象,使他们能够连接到NFC。 此前它的工作在某种程度上,但现在我已经得到了问题 - 我的应用程序不会做任何事情onNewIntent,甚至在第一个活动。代替它,我可以看到内置的应用程序称为标签(歌Nexus S)收集的新标签。

我应该怎么办?

类:

 公共NFCForegroundUtil(活动活动)
{
    超();
    this.activity =活动;
    mAdapter = NfcAdapter.getDefaultAdapter(活动
            .getApplicationContext());

    mPendingIntent = PendingIntent.getActivity(活动,0,新的意向(
            活性,activity.getClass())
            .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP),0);

    IntentFilter的NDEF =新的IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter的ndef2 =新的IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter的ndef3 =新的IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

    尝试
    {
        ndef2.addDataType(* / *);
    }
    赶上(MalformedMimeTypeException E)
    {
        抛出新的RuntimeException(不及格,E);
    }

    mFilters =新的IntentFilter [] {NDEF,ndef2,ndef3};

    mTechLists =新的String [] [] {新的String [] {
            // android.nfc.tech.NfcV.class.getName(),
            android.nfc.tech.NfcA.class.getName(),
            android.nfc.tech.IsoDep.class.getName()}};

    mAdapter.enableForegroundDispatch(这一点,mPendingIntent,mFilters,mTechLists);

}
 

活动1:

  @覆盖
公共无效的onCreate(包savedInstanceState)
{
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.main);

    nfcForegroundUtil =新NFCForegroundUtil(本);

}

 @覆盖
保护无效onNewIntent(意向意图)
{

    super.onNewIntent(意向);
    意图I =新的意图(这一点,NfcDisplayLabelActivity2.class);
    startActivity(ⅰ);

 }
 

解决方案

我看到收集新标签,从内置的应用程序称为标签,因为我的应用程序没有正常工作。

当它工作正常,它具有更高的优先级比标签和手机读取标签,从我的应用程序。但是,当它工作unproperly和电话收集了标签,标签的应用程序被激活,标签的应用程序会谈到我的设备。

修理code后,我的应用程序具有更高的优先级,并使用我的应用程序的手机读取标签。

I have a class, which creates conncection to NFC and two activites. Both of them creates an object of that class so they can connect to NFC. Earlier it worked somehow but now I've got problem - my application doesn't do anything onNewIntent, even on the first activity. Instead of it, I can see "New tag collected" from build-in app called "Tags" (Nexus S).

What should I do?

class:

public NFCForegroundUtil(Activity activity)
{
    super();
    this.activity = activity;
    mAdapter = NfcAdapter.getDefaultAdapter(activity
            .getApplicationContext());

    mPendingIntent = PendingIntent.getActivity(activity, 0, new Intent(
            activity, activity.getClass())
            .addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);

    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_TAG_DISCOVERED);
    IntentFilter ndef2 = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    IntentFilter ndef3 = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);

    try
    {
        ndef2.addDataType("*/*");
    }
    catch (MalformedMimeTypeException e)
    {
        throw new RuntimeException("fail", e);
    }

    mFilters = new IntentFilter[] {ndef, ndef2, ndef3 };

    mTechLists = new String[][] { new String[] {
            // android.nfc.tech.NfcV.class.getName(),
            android.nfc.tech.NfcA.class.getName(),
            android.nfc.tech.IsoDep.class.getName() } };

    mAdapter.enableForegroundDispatch(this, mPendingIntent, mFilters, mTechLists);

}

activity 1:

@Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    nfcForegroundUtil = new NFCForegroundUtil(this);

}

 @Override
protected void onNewIntent(Intent intent)
{

    super.onNewIntent(intent);
    Intent i = new Intent(this, NfcDisplayLabelActivity2.class);
    startActivity(i);

 }

解决方案

I was seeing "New tag collected" from build-in app called "Tags" because my application didn't work properly.

When it works ok, it has higher priority than "Tags" and phone reads tags from my application. But when it works unproperly and phone collect a tag, "Tags" application is activated and "Tags" application talks to my device.

After repairing code, my app has higher priority and phone reads tags using my application.

这篇关于[新增标签收集"而不是阅读应用标签 - NFC的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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