I have an Android activity that when in contact with an NFC tag calls a certain function. I would like to create tests for that.
In my test file, my logic is as follows:
// Create a ACTION_TAG_DISCOVERED
// Respond to ACTION_TAG_DISCOVERED
public void testNfc(){
}
In my code, I have a callback function “onNewIntent” which looks at the intent created when in proximity to an NFC tag:
protected void onNewIntent(Intent intent) {
if (NfcAdapter.ACTION_TAG_DISCOVERED.equals(intent.getAction())) { ... }
But, in my test code, I cannot create an Intent of ACTION_TAG_DISCOVERED. I looked at the class here.
How do I create an ACTION_TAG_DISCOVERED intent so I can test it? Somewhere along this line:
Intent nfcIntent = new Intent(Intent.ACTION_TAG_DISCOVERED)
if(nfcIntent == ACTION_TAG_DISCOVERED)
assertSomeMethod("functionWhichHandlesNFCTagDiscovered")
Thanks much!
Try using this: ACTION_TAG_DISCOVERED
I haven’t tested it, but if you make an Intent like so:
you may be able to do what you’ve described.