Question

I've been trying to find a way to instantiate the Tag object. I'm trying to do this so that i can simulate various types of Tags.

Does anyone know how to get an instance of UltraLight object using

Tag tag = ?????
UltraLight obj = UltraLight.get(tag);

Thank you

Was it helpful?

Solution

In the NFC app example for ICS source code, we can find some code such as:

Bundle extras = new Bundle();
extras.putParcelable(Ndef.EXTRA_NDEF_MSG, ndefMsg);
extras.putInt(Ndef.EXTRA_NDEF_MAXLENGTH, 0);
extras.putInt(Ndef.EXTRA_NDEF_CARDSTATE, Ndef.NDEF_MODE_READ_ONLY);
extras.putInt(Ndef.EXTRA_NDEF_TYPE, Ndef.TYPE_OTHER);
Tag tag = Tag.createMockTag(new byte[] { 0x00 },
    new int[] { TagTechnology.NDEF },
    new Bundle[] { extras });

Code for this createMockTag method is following:

public static Tag createMockTag(byte[] id, int[] techList, Bundle[] techListExtras) {
    // set serviceHandle to 0 to indicate mock tag
    return new Tag(id, techList, techListExtras, 0, null);
}

Maybe this could help.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top