I am trying to mock an NFC Tag with an in-app developer mocking tool. The current implementation uses reflection and is targeting API 27. Migrating to API 28 with AndroidX, the method createMockTag
is not found. I notice that it's public static
in the Android code, but is annotated with @Hide
, meaning that I can't access it. I have found a way, however, to create a Tag from a Parcel, but I have not found anywhere a simple way to do it. I can create my own Parcelable class, but when calling in.readInArray(...)
in the constructor, it asks for a parameter that I don't have. I will attach what it looks like know and what I'd like it to look like.
This is a big issue because we need to mock NFC Tags, but there doesn't seem to be a way to access the method. And I've also tried to copy the Tag.java
class into my project, but it can't access certain seemingly-internal classes such as INfcTag
and the enums in TagTechnology
. Has anyone else come across this and can please help me? Thank you.
// Tag mockTag = Tag.CREATOR.createFromParcel(); // I'd like to create one here
Method createMockTag = Tag.class.getMethod("createMockTag", byte[].class, int[].class, Bundle[].class);
scanIntent.putExtra(NfcAdapter.EXTRA_TAG, (Tag) createMockTag.invoke(Tag.class, tagId, new int[]{}, new Bundle[]{}));
Here are links I've looked at:
- https://www.vogella.com/tutorials/AndroidParcelable/article.html
- https://guides.codepath.com/android/using-parcelable
- How do i create an Tag object in android?
- Identifying NFC tag ID
- https://www.google.com/search?client=safari&rls=en&q=android+9+nfc+not+working&ie=UTF-8&oe=UTF-8
- https://www.google.com/search?client=safari&rls=en&biw=1080&bih=923&ei=68ijXMnoDoHisAXPjLzQCA&q=public+static+Tag+createMockTag%28byte%5B%5D+is%2C+int%5B%5D+techList%2C+Bundle%5B%5D+techList+Extras%29+%7B&oq=public+static+Tag+createMockTag%28byte%5B%5D+is%2C+int%5B%5D+techList%2C+Bundle%5B%5D+techList+Extras%29+%7B&gs_l=psy-ab.3...107084.107084..107212...0.0..0.0.0.......0....1..gws-wiz.rfrM415Sx7o
- https://developer.android.com/about/versions/pie/android-9.0
- https://developer.android.com/reference/android/nfc/package-summary.html
- https://developer.android.com/sdk/api_diff/28/changes.html
- https://developer.android.com/reference/android/os/Parcelable.Creator
- And probably several more whose tabs I've closed or navigated away from.