Android Deeplink

Deep linking

To create a link to your app content, add an intent filter with specific elements and attribute values to your manifest. The following XML snippet illustrates how you might specify an intent filter in your manifest for deep linking. Both the URIs "example://gizmos" and "http://www.example.com/gizmos" will resolve to this activity.

<activity
    android:name="com.example.android.GizmosActivity"
    android:label="@string/title_gizmos" >
    <intent-filter android:label="@string/filter_view_http_gizmos">
        <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="/gizmos" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
    <intent-filter android:label="@string/filter_view_example_gizmos">
        <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 "example://gizmos” -->
        <data android:scheme="example"
              android:host="gizmos" />
    </intent-filter>
</activity>

Note that the two intent filters only differ by the data element. While it's possible to include multiple data elements in the same filter, it's crucial to create separate filters when declaring unique URLs, such as a specific combination of scheme and host. This is important because multiple data elements in the same intent filter are merged together to account for all variations of their combined attributes. For example, consider the following:

<!-- Custom in-app message style -->
<intent-filter>
  ...
  <data android:scheme="https" android:host="www.example.com" />
  <data android:scheme="app" android:host="open.my.app" />
</intent-filter>

While it may seem that this supports only https://www.example.com and app://open.my.app, it actually covers those two as well as app://www.example.com and https://open.my.app.

After you've added intent filters with URIs for activity content to your app manifest, Android can route any Intent with matching URIs to your app at runtime.

Once the deep link definitions are complete, if you import the following method into build.gradle (app), users will be redirected to the deep link by the Netmera SDK when they click the notification. The Netmera SDK directs the user to the deep links defined in the manifest.

android {
  ...
    defaultConfig {
      ...
        //following line is for automatic deep link.
        //If you dont want Netmera to handle deeplinks you should set that value to false.
        resValue "bool", "netmera_use_default_deeplink_action", "true"
      ...
    }
}

You can also obtain the deep link URI from the NMPushActionCallbacks class.

public class NGPushActionCallbacks implements NMPushActionCallbacks {

  @Override
  protected void onPushOpen(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {

    Uri deeplinkUri = netmeraPushObject.getDeepLink();
  }
}

For more detailed information on deep linking in Android, you can refer to the official Android documentation: Android Deep Linking

Configure the Project

Set android:autoVerify="true" in one of the web URL intent filters in the app manifest that includes the android.intent.action.VIEW intent action and android.intent.category.BROWSABLE intent category.

<!-- Custom in-app message style -->
<activity ...>
    <intent-filter android:autoVerify="true">
        <action android:name="android.intent.action.VIEW" />
        <category android:name="android.intent.category.DEFAULT" />
        <category android:name="android.intent.category.BROWSABLE" />
        <data android:scheme="http" android:host="www.naturalworld.com" />
        <data android:scheme="https" />
    </intent-filter>
</activity>

Configure the website

Create an assetlinks.json file with package_name (the application ID declared in the app's build.gradle file) and sha256_cert_fingerprints (the SHA256 fingerprints of the app’s signing certificate).

[{
"relation": ["delegate_permission/common.handle_all_urls"],
"target": {
"namespace": "android_app",
"package_name": "com.netmera.naturalworld",
"sha256_cert_fingerprints":
["XX…XX"]
}
}]

Host the assetlinks.json file. Publish the assetlinks.json file on the domain. Ensure it is hosted on the website to indicate the association of Android apps with the website and to verify the app's URL intents.

You can also retrieve the universal link URL from the NMPushActionCallbacks class.

public class NGPushActionCallbacks implements NMPushActionCallbacks  {

  @Override
  protected void onPushOpen(Context context, Bundle bundle, NetmeraPushObject netmeraPushObject) {

    Uri universalLinkUrl = netmeraPushObject.getDeepLink();
  }
}

Last updated