2
votes

When a NFC tag is brought closer in the vicinity of the phone, Android OS creates a NFC Tag object and starts the foreground dispatcher.

My problem, is that I don't have a NFC phone and I was trying to create my own tag object and start an intent which later on Android OS will take care to divert that intent to a particular app on my emulator.

Is it possible to create a NFC Tag object via code?

4

4 Answers

3
votes

No, sorry. There is no way to emulate NFC effectively. I suggest that you wait on this application until you can acquire an NFC-capable Android device.

1
votes

it is definitely possible to mimic an NFC tag being scanned. See

http://developer.android.com/resources/samples/NFCDemo/src/com/example/android/nfc/simulator/FakeTagsActivity.html

for an example. The NFC Demo sample that this class is in is somewhat dated and you need these libraries to compile it: http://code.google.com/p/guava-libraries/, but it should show you what you need to do.

You basically just need to create your NDEF message, specify that as an NFC intent extra (EXTRA_NDEF_MESSAGES) and specify the intent, such as ACTION_NDEF_DISCOVERED, and then call startActivity(intent).

0
votes

@Sana If you are developing on a windows system, i suggest you check out Open NFC.

In it is a Simulator tool which can be used to simulate NFC tags, but the only drawback is, the Android image that is emulated is Gingerbread and not ICS (which they are working, with haste is hope).

Otherwise, i have the same problem. I was wondering if someone with an NFC reader phone can write a simple code, which will simply persist the Tag Object so that people without an nfc reader can actually unserialize that object and use to simulate!

0
votes

You can also duplicate the NDEF_DISCOVERED IntentFilter as a new IntentFilter that catches basicly the same thing.

Write the data you want to write in a tag in a QR code. And scan it. The phone will open the same activity with the same data. It will be kinda emulate the same reponse when you use an actual NFC tag.