Deep Linking in Android Application

Posted By : Kishan Gupta | 14-May-2018

Deep Linking is a Mechanism that programmatically requests to invoke an android application on a specific resource. When the user clicks the link - it invokes a web URI intent, the Android operating system does try each of the following action, until request gets succeed:

  • It open user preferred application If the user has already selected their preferred application.
  • If user haven't made any preference than it offers an available application that can handle the URI.
  • All user to select an application and proceed with selected one.

To create a link to your content follows the below steps. Android Studio with 3.0 and more have APP Links Assistant to help developers.

To add a deep link to your application, add an intent filter that contains following  attribute and element values in the manifest:

  • <action>  To reach intent filter from search,action specify the ACTION_VIEW intent action.
  • another tag is <data> which is used in this process, each <data> tag represent URI format that resolves to activity. Minimum, this tag must contain the android: scheme attribute, Whereas we can have more than one <data> tag for further refine the type of URI. In that case, use android: path attribute of pathPrefix or pathPattern variables to differentiate.
  • <category> is that last tag which is used in this process. It includes DEFAULT category which allows the app to respond to the implicit intent and it also includes the BROWSABLE category in order to access it from web browser.?
 
<activity
    android:name="com.example.android.GizmosActivity"
    android:label="@string/title" >
    <intent-filter android:label="@string/view_http">
        <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 "https://www.deepLinkExample.com/example1” -->
        <data android:scheme="https"
              android:host="www.deepLinkExample.com"
              android:pathPrefix="/example1" />
        <!-- note that the leading "/" is required for pathPrefix-->
    </intent-filter>
    <intent-filter android:label="@string/view_example">
        <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 "deepLinkExample://example1” -->
        <data android:scheme="deeplinkexample"
              android:host="example1" />
    </intent-filter>
</activity>


Once android start your activity through Intent filter. you can use the data provide by intent ,call getData() and getAction() to retrive the data and action from the intent and take the required action.

 
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_layout);

    Intent intentData = getIntent();
    String actionIntent = intent.getAction();
    Uri dataUri = intentData.getData();
}

Here we have successfully integreted the Deep Link in android application 

Happy Coding :)

About Author

Author Image
Kishan Gupta

Young, Enthusiastic, Never give up Attitude are the perfect words to define Kishan. He is committed to learn and dedicated to work. He believes in "Think Big Get Big"

Request for Proposal

Name is required

Comment is required

Sending message..