The current app intercepts the NFC response and does not pop up the selection box tutorial

Source: Internet
Author: User

from the previous NFC support type of card read, the following is to solve the NFC blocking response, if this step is not done, when the system has a number of NFC-enabled applications, will be in the NFC swipe when the number of application options, we need the scene is, The current app requires NFC to swipe, and the app intercepts intent distribution (using theForeground Dispatch System).

Specific scenarios:

1. Create pendingintent to distribute the activity you want to respond to

  Mpendingintent = pendingintent.getactivity (this, 0,                new Intent (this, nfcactivity.class). Addflags (Intent.flag_ Activity_single_top), 0);

2. When swiping, use the intent filter to filter out the intent you want to intercept.

  Intentfilter ndef = new Intentfilter (nfcadapter.action_ndef_discovered);        try {            ndef.adddatatype ("*/*"),        } catch (Intentfilter.malformedmimetypeexception e) {            throw new RuntimeException ("fail", E);        }        Intentfiltersarray = new Intentfilter[]{ndef,};

3. Set the tag technologies you want to handle in the string array

Techlistsarray = new String[][]{new String[]{nfca.class.getname ()}};

4. Set the Nfcadapter in Onresume and OnPause

public void OnPause () {    super.onpause ();    Madapter.disableforegrounddispatch (this);} public void Onresume () {    super.onresume ();    Madapter.enableforegrounddispatch (This, pendingintent, Intentfiltersarray, Techlistsarray);}
Of course, before you define Nfcadapter

  Nfcadapter = Nfcadapter.getdefaultadapter (this);
This problem to solve the experience of one thing, this issue in the domestic blog forum has not been searched, there is an article on the StackOverflow

http://stackoverflow.com/questions/16542147/ How-to-read-nfc-tags-to-prevent-system-dialogs-nfc-starter-list-and-tags-being-d

The link inside is the Android develop ... NFC foreground dispatching.

All the basic tutorials can be found in the developer, no longer blind toss, there are problems to find Google




The current app intercepts the NFC response and does not pop up the selection box tutorial

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.