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:
new NdefMessage(new NdefRecord[] {
NdefRecord.createUri("http://example.com/viewer/ + id + "?tab=" + tab),
// TODO: add more records if you want to provide additional data to YOUR app if it is installed
});
Then you would use an NDEF_DISCOVERED
intent filter in your app's manifest to catch that specific URI:
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="http" android:host="example.com" android:pathPrefix="/viewer/" />
</intent-filter>
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 for NDEF_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:
- You should not use more than one Android Application Record (AAR). Only one of them will be effective.
- If you use an AAR for your app, you make it impossible for the web browser to catch the URI in case your app is not installed. Instead, your app's Play Store listing will be opened.
- Using something other than a URI as the first record will make automatic launching of the default web browser impossible if your app is not installed.