bbedward
bbedward

Reputation: 6478

Android Deep Link with a URI that contains no paths but data-only

I want to add support for a deep link of a URI with the following scheme:

xrb:xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp?amount=10000

The amount parameter is optional, the second part is a required address. So essentially the schema is xrb: the first part xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp is any string and amount is an optional parameter.

Looking at the Android documentation here, what I'm not clear about is how to retrieve the data from my activity, particularly for the part that doesn't come in as a parameter (xrb_3wm37qz19zhei7nzscjcopbrbnnachs4p1gnwo5oroi3qonw6inwgoeuufdp)

The URI is a standard that other applications and services use so I'd rather not change it or do anything proprietary, but is it possible to have a deep link with a URI of this format?

Basically all I'm looking for is when clicking a link containing the URI, the app will open and pre-load some data for them based on the URI.

Thanks!

Upvotes: 1

Views: 282

Answers (1)

bbedward
bbedward

Reputation: 6478

Accomplished by creating an intent-filter in AndroidManifest

<!-- xrb uri scheme -->
<intent-filter android:label="@string/app_name">
    <action android:name="android.intent.action.VIEW" />
    <action android:name="android.nfc.action.NDEF_DISCOVERED" />

    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />

    <data android:scheme="xrb" />
</intent-filter>

And retrieving the URI in the activity's onCreate

Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
if (data != null) {
    Timber.d("inuri %s", data.toString());
} else {
    Timber.d("inuri null");
}

Upvotes: 3

Related Questions