Need To Fake an NFC Tag Being Scanned In Android
Asked Answered
N

2

4

Ok, I have an app. This app will only complete a task when an nfc tag, any tag, is scanned. Only problem, I do not have any nfc tags. And I am trying to eliminate needing a card anyway, So What I need is a way to "Fake/Make It Look" Like an nfc tag has been scanned. I can write apps and such so all I really need is the core code to make android think a tag was scanned. I can do the rest. I just need to be able to push a button, then android think that a tag was scanned so that the app will be invoked. Thank You Guys

Norling answered 24/9, 2012 at 0:44 Comment(1)
Consider buying a tag as that is likely to be cost-efficient. Get a single 1K tag, it will probably be sufficient. – Weaponry
K
1

Write an app that broadcasts the NFC intent you'd like to emulate upon launch, and then closes. So a simple app with a single activity that does roughly this in its onCreate:

       Intent intent = new Intent("android.nfc.action.NDEF_DISCOVERED");
       startActivity(intent);
       finish();

Then your app should volunteer to handle it as though it had been read with an NFC reader.

In the end Thomas is right, you should just buy an NFC tag and be done with it, that way you know that it's doing what you want it to for normal nfc tags.

If that doesn't quite float your boat, another option is to add a long-running notification, upon the click of which, it does the intent broadcast. This way you won't have to go back to the main menu to get it to work.

Knott answered 25/10, 2012 at 16:51 Comment(3)
Why NDEF_DISCOVERED instead of ACTION_TECH_DISCOVERED? – Longdrawn
Late for the game by 11 years πŸ˜…, but you can also just trigger an intent from the terminal using ADB: "adb shell am start -a android.nfc.action.NDEF_DISCOVERED -d "[data you want delivered]" -c android.intent.category.DEFAULT – Gabble
@LeoFarage, you should write an anwser with this as this is definitely the right solution! However it didn't work for me straight away. – Autoplasty
A
1

The easiest foloowing @LeoFarage comment is to do it from ADB:

am start -a android.nfc.action.NDEF_DISCOVERED -d "[TEST]" -t text/plain -c android.intent.category.DEFAULT

This matches the following manifest definition:

        <intent-filter>
            <action android:name="android.nfc.action.NDEF_DISCOVERED" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="text/plain" />
        </intent-filter>

Sadly it doesn't work when using code like this:

nfcAdapter.enableReaderMode(...
Autoplasty answered 12/12, 2023 at 9:49 Comment(0)

© 2022 - 2024 β€” McMap. All rights reserved.