Is there a way to construct a NdefMessage
in such way that:
I got these working separately but when I put two NdefRecord
into a NdefMessage
and set it to be pushed via Android Beam, the receiver device displays a chooser with these two records. You can click one of these and it will take you to the appropriate app (my app or Chrome). Is there a way to bypass this chooser and make it launch first supported link automatically?
If you don't need to use AndroidApplicationRecords, you can simply use a single NDEF record that points to your mobile page.
For instance if your mobile page is http://www.example.com/mypage, you would store this as a URI record in the NDEF message:
+-----------------------------------------+
| WKT:URI | http://www.example.com/mypage |
+-----------------------------------------+
Then, if your application is not installed, this will trigger the webbrowser on the mobile device.
To get this record to start you app, you would need to add a proper intent filter to your app's manifest:
<activity ...>
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http"
android:host="www.example.com"
android:pathPrefix="/mypage" />
</intent-filter>
</activity>
If you want to pass additional data to your application, you can -- of course -- add a second record (after the URI record) that contains you custom data. In that case, you NDEF message could look like this:
+-----------------------------------------+
| WKT:URI | http://www.example.com/mypage |
+-----------------------------------------+
| EXT:example.com:mytype | myparameters |
+-----------------------------------------+
| ... |
As the first record in that message is still your URI, the activity will continue to trigger on the existing intent filter. Within the activity, you can then retrieve the NDEF message from the intent and process the parameters from the second record/other records.