How attach Tag intent extra for NFC-Tag scan simulation through ADB shell?

465 views Asked by At

I am trying to execute

adb shell am start -W -a android.nfc.action.NDEF_DISCOVERED -d "https://www.google.de"

in a way that would be similar to an actual NFC-Tag scan which has some URI (SmartPoster).

This is necessary, as the above command works e.g. with Chrome but not as a deeplink into a Capacitor app.

As far as I've discovered, it is necessary to send some extra data to this intent in order for this to work correctly as a deeplink for my use case.

However, I'm not really an android-dev and the docs are lacking examples regarding the correct syntax and contents of these extras.

According to https://developer.android.com/studio/command-line/adb#IntentSpec

These are the possible extra options to set:

-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE>
--esn <EXTRA_KEY>
--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE>
--ei <EXTRA_KEY> <EXTRA_INT_VALUE>
--el <EXTRA_KEY> <EXTRA_LONG_VALUE>
--ef <EXTRA_KEY> <EXTRA_FLOAT_VALUE>
--eu <EXTRA_KEY> <EXTRA_URI_VALUE>
--ecn <EXTRA_KEY> <EXTRA_COMPONENT_NAME_VALUE>]
--eia <EXTRA_KEY> <EXTRA_INT_VALUE>[,<EXTRA_INT_VALUE...]
--ela <EXTRA_KEY> <EXTRA_LONG_VALUE>[,<EXTRA_LONG_VALUE...]
--efa <EXTRA_KEY> <EXTRA_FLOAT_VALUE>[,<EXTRA_FLOAT_VALUE...]

(copied from: https://stackoverflow.com/a/26517290)

And there seems to be a new option for string arrays:

[--esa <EXTRA_KEY> <EXTRA_STRING_VALUE>[,<EXTRA_STRING_VALUE...]]
(to embed a comma into a string escape it using "\,")

(copied from https://stackoverflow.com/a/28638589)

According to google, the EXTRA_TAG ist passed as the extra for the intent.

When a tag is discovered, a Tag object is created and passed to a single activity via the NfcAdapter#EXTRA_TAG extra in an android.content.Intent via android.content.Context#startActivity.

Mandatory extra containing the Tag that was discovered for the ACTION_NDEF_DISCOVERED, ACTION_TECH_DISCOVERED, and ACTION_TAG_DISCOVERED intents.

The value of EXTRA_TAG is android.nfc.extra.TAG - see here


So my best guess currently is that something like this might work:

adb shell am start -W -a android.nfc.action.NDEF_DISCOVERED -d "https://www.google.de" --es android.nfc.extra.Tag 'flattened object?!'

Question: Does anybody know how to execute this correctly?

Thank you very much for your help!

1

There are 1 answers

0
Vince On

I am not sure what you already know and what you don't know about the tag content and the app reading the tag.

In the most simple case, reading the Intent data (or dataString) will be enough.

I am myself looking for the same kind of information as I don't have the specifications of the NFC tag the app should read. So your first guess is probably the right one:

adb shell am start -W -a android.nfc.action.NDEF_DISCOVERED -d "https://www.google.de"

But maybe your NFC tag contains the url in the extra tag you mentioned. In that case, that would be:

adb shell am start -W -a android.nfc.action.NDEF_DISCOVERED --es android.nfc.extra.Tag "https://www.google.de"

It is also possible that the url is stored in one of the NDEF messages, as it is another option to carry data. I personally did not manage to find the correct adb command to trigger that intent but that little bit might help some others.