Simple deeplinking

These are instructions to support and test simple deeplinking, without Firebase or the Navigation Components.

AndroidManifest.xml

Add an Intent filter to your manifest and specify which URLs should open your Activity:

<intent-filter android:label="@string/filter_title_viewgizmos">
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT" />
    <category android:name="android.intent.category.BROWSABLE" />
    <!-- Accepts URIs that begin with "http://www.example.com/gizmosā€ -->
    <data android:scheme="http"
          android:host="www.example.com"
          android:pathPrefix="/stuff" />
    <!-- note that the leading "/" is required for pathPrefix-->
    <!-- note that only one <data> per intent-filter is allowed -->
</intent-filter>

YourActivity.java

Handle the URL inside your Activity:

Intent intent = getIntent();
String action = intent.getAction();
Uri data = intent.getData();
String relevantPart = data.getLastPathSegment();

Testing

Test it through the command line:

adb shell am start -W -a android.intent.action.VIEW -d http://www.example.com/stuff/

Or, when using the adb.sh script, like so:

./adb.sh open http://www.example.com/stuff/