Need To Fake an NFC Tag Being Scanned In Android

2019-07-15 11:37发布

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

1条回答
孤傲高冷的网名
2楼-- · 2019-07-15 12:23

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.

查看更多
登录 后发表回答