Skip to content

Instantly share code, notes, and snippets.

@kurosabo
Created February 9, 2021 01:14
Show Gist options
  • Save kurosabo/427da980102011f4c7a76c92f6b446d2 to your computer and use it in GitHub Desktop.
Save kurosabo/427da980102011f4c7a76c92f6b446d2 to your computer and use it in GitHub Desktop.
sesame3 control from myapp
private void sendTagIntent(){
// 参考 https://stackoverflow.com/questions/30841803/how-to-mock-a-android-nfc-tag-object-for-unit-testing
// 参考2 https://developer.android.com/distribute/best-practices/develop/restrictions-non-sdk-interfaces?hl=ja
byte[] tagId = {(byte)0xXX, (byte)0xXX, (byte)0xXX, (byte)0xXX, (byte)0xXX, (byte)0xXX, (byte)0xXX}; // you're tag id
int[] techList = new int[0];
Bundle[] techListExtras = new Bundle[0];
Class tagClass = Tag.class;
Method createMockTagMethod = null;
try {
createMockTagMethod = tagClass.getDeclaredMethod("createMockTag", byte[].class, int[].class, Bundle[].class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
}
Tag mockTag = null; // array of tech-extra bundles, each entry maps to an entry in the tech-list
try {
assert createMockTagMethod != null;
mockTag = (Tag)createMockTagMethod.invoke(null,
tagId, // tag UID/anti-collision identifier (see Tag.getId() method)
techList, // tech-list
techListExtras);
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
Intent sendIntent = getPackageManager().getLaunchIntentForPackage("co.candyhouse.sesame2");
sendIntent.setAction(NfcAdapter.ACTION_NDEF_DISCOVERED);
sendIntent.setType("text/plain");
sendIntent.putExtra(NfcAdapter.EXTRA_TAG, mockTag);
startActivity(sendIntent);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment