开发者

Android NFC TECH_DISCOVERED with foreground dispatcher

I am programming an NFC application in Android and I have a little problem when writing tags. I have been able to write a tag but in order to do it I detect it using intent-filters in the manifest. However, what I want to do is to deal with the tag directly with the application using the foreground dispatcher. I am able to "catch" NDEF_DISCOVERED tags with the foreground dispatcher but I don't know how to use TECH_DISCOVERED in the same fashion.

This code works with NDEF_DISCOVERED:

    // Setup an intent filter for all MIME based dispatches
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
        ndef.addDataType("*/*");
   } catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    }
   mFilters = new IntentFilter[] {
            ndef,
    };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.getName() } };

But what should I do for TECH_DISCOVERED???? I'm trying this and it doesn't work:

    IntentFilter ntech = new IntentFilter(NfcAdapter.ACTION_TECH_DISCOVERED);


   mFilters = new IntentFilter[] {
            ntech,
    };

    // Setup a tech list for all NfcF tags
    mTechLists = new String[][] { new String[] { NfcF.class.g开发者_如何学编程etName() } };
}


I hope you would have figured it by yourself. However, for the people who didn't: You should specify the appropriate Tag Technology in the mTechLists, which you expects to process. There is no need to change the intent filter to specify ACTION_TECH_DISCOVERED, it should work fine with ACTION_NDEF_DISCOVERED. Cheers!!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜