I want to beam the content of my currient screen. Basically I have three tabs with long lists, I want to beam the actual tab and its position.
My goal is if the app is installed:
Beam some id, the tab and position
If the app is not installed:
I want to offer a weblink like this http://example.com/viewer/42?tab=2
I'm playing with this code here:
adapter.setNdefPushMessageCallback(new CreateNdefMessageCallback() {
@Override
public NdefMessage createNdefMessage(NfcEvent event) {
return new NdefMessage(new NdefRecord[] {
NdefRecord.createExternal("com.example.android", "viewer", getData()),
NdefRecord.createUri(VIEWER_URL + id + "?tab=" + tab),
NdefRecord.createApplicationRecord("com.example.android"),
NdefRecord.createApplicationRecord("com.android.browser"),
});
}
}, this);
I would be happy if someone could explain me how that works and if this is not possible to explain me why this is impossible.
As @NFC guy already explained, the way to go is to Beam your URI (and only that URI, or at least that URI as the first record of that NDEF message). So your NDEF message would look something like that:
Then you would use an
NDEF_DISCOVERED
intent filter in your app's manifest to catch that specific URI:If the URI belongs to you (i.e. if no other app registers for a URI that starts with
http://example.com/myapp/
) and your app ins installed, there will be no intent chooser (as the more specific URI will take precedence). If your app is installed, it will receive the URI. If it's not installed, the browser will open the URI, or if other apps registered forNDEF_DISCOVERED
with only the scheme "http", there will be an intent chooser (though usually other apps than web browsers should usually register for a more specific URI).Regarding your current NDEF message: