Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8451979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T11:23:07+00:00 2026-06-10T11:23:07+00:00

Ok so I’ve been bangin away at my first Android app and the NFC

  • 0

Ok so I’ve been bangin away at my first Android app and the NFC has been very hit and miss. I’m able to successfully pickup on plain text type records, but when I switch over to try to pickup on uri records the phone’s browser keeps opening rather than my app. I’m clueless at this point so here’s what I got…

<activity
        android:name=".MainActivity"
        android:label="@string/title_activity_main" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <data android:scheme="http" android:host="google.com"/>
        </intent-filter>
        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
            <data android:mimeType="text/plain"/>
            <category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
    </activity>

When I read the tag, I get a new intent but it’s action type is “MAIN”. Is it just being relaunched? And if so why doesn’t the text record do the same? I’ve tried multiple uri records and every time I get this behavior. Here is part of the java src.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    Intent launchIntent = getIntent();
    String action = launchIntent.getAction();
    if(action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
        Log.i(tag, "MATCH!");
    }


    nfcAdapter = NfcAdapter.getDefaultAdapter(this);
    nfcPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
    tagDetected = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);

    tagDetected.addDataScheme("http");
    tagDetected.addDataAuthority("google.com", null);
    filters = new IntentFilter[] { tagDetected };

    techArray = new String[][] {
            new String[] {
                    IsoDep.class.getName()
            },
            new String[] {
                    NfcB.class.getName()
            },
            new String[] {
                    Ndef.class.getName()
            }
    };

}

public void onResume(){
    super.onResume();



    nfcAdapter.enableForegroundDispatch(this, nfcPendingIntent, filters, techArray);

    Intent launchIntent = getIntent();
    String action = launchIntent.getAction();
    if(action.equals(NfcAdapter.ACTION_NDEF_DISCOVERED)) {
        Log.i(tag, "MATCH!");
    } else if(action.equals(NfcAdapter.ACTION_TECH_DISCOVERED)) {
        Log.i(tag, "TECH DISCOVERED");

    } else if(action.equals(NfcAdapter.ACTION_TAG_DISCOVERED)) {
        Log.i(tag, "TAG DISCOVERED");
    }

    Parcelable[] msg = launchIntent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    //byte[] payloadData = msg.getRecords()[0].getPayload();
    //Log.i(tag, "NUM records = " + Integer.toString(msg.getRecords().length));


}


public void onPause() {
    super.onPause();

    nfcAdapter.disableForegroundDispatch(this);
}

Another interesting note is that when I don’t include the list of technologies in the enableForegroundDispatch() call, then the app doesn’t pickup any intents resulting from NFC at all (when trying to read uri records). Any ideas oh wise internet?!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T11:23:09+00:00Added an answer on June 10, 2026 at 11:23 am

    With ForegroundDispatch enabled, the intent will arrive through onNewIntent(), so you need to override that method in your activity to receive the NFC intent.

    You also need to make sure that the hostname matches exactly. If the tag contains “www.google.com”, your intent filter should contain the same name: <data android:scheme="http" android:host="www.google.com"/> and tagDetected.addDataAuthority("www.google.com", null).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
In my XML file chapters tag has more chapter tag.i need to display chapters

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.