What is Deep Link?
- A Deep Link is a URI of any scheme that takes the user directly to a specific part of your application.
- Using this URL we can send a message to our application with parameters.
What is it used for?
- Deep Links are used for directing users to specific parts of your application, or other applications all together.
- This allows for the user to bypass certain parts of your application allowing for an easier experience.
How to create Deep Links
- You will have to first define an
intent-filter
for it within yourAndroidManifest.xml
file.- These drive users to the right activity in your application.
Looks like this:
Let’s go through what each tag and it’s attribute means.
- The
<activity>
tag is defines the activities we have within our application.android:name
attribute specifies the name of the activity.android:exported
attribute declares that this activity is accessible outside this application.
- The
<intent-filter>
tag declares what type of intents this application can respond to.android:autoVerify
attribute ensures that the deep link is verified within our system.- If it’s set to
true
, the system tries to verify that the specified domain is associated with your application.
- If it’s set to
<action>
tag specified the action that your application can handle.android:name
attribute defines the action nameandroid:intent.action.VIEW
tells the system that this activity can respond to aview
actions.
<category>
tag adds a category to ourintent-filter
, which specifies additional information about the kinds ofIntents
the activity can handle.android.intent.category.DEFAULT
declares our activity as an entry point to our applicationandroid.intent.category.BROWSABLE
declares that our activity is capable of being reached via a web link. This makes it accessible to web browsers and other applications.
<data>
tag specifies the data that theURI
pattern can handle.android:scheme
attribute defines the URI scheme(e.g.HTTP
,HTTPS
, or a custom scheme likeexample
).android:host
attribute specifies the host part of the URI(e.g.,www.example.com
or a custom host likecontent
).android:pathPrefix
attribute defines the initial part of the path that theURI
must match.- In this case, it matches with URIs starting with
/path/to/content
- So with our given configuration our
MainActivity
can handle deep links that match the following patternexample://content/path/to/content
example
being the custom schemecontent
being the custom host/path/to/content
being the path
- In this case, it matches with URIs starting with
Deep Linking to launch other applications
- Configure Deep Linking in Your Application
- Handle the Deep Link in Your Activity
- Launch Your App via Deep Link from Another Application
1. Configure Deep Linking in Your Application
- Set up deep link in your applications
AndroidManifest.xml
Example:
In this configuration:
- The
android:scheme
is set toexample
. - The
android:host
is set tocontent
. - The
android:pathPrefix
is set to/path/to/content
.
2. Handle the Deep Link in Your Activity]
In your MainActivity
, handle the incoming deep link.
Example:
3. Launch Your App via Deep Link from Another Application
In the other application, create an Intent
that uses a deep link URI to launch your application.
Example code from other application:
Summary
-
Configure Deep Linking in Your App:
- Set up the
intent-filter
in your app’sAndroidManifest.xml
to handle the specific deep link URI.
- Set up the
-
Handle the Deep Link in Your Activity:
- Implement logic in your activity to parse and respond to the deep link.
-
Launch Your App via Deep Link from Another App:
- Create an intent with the deep link URI and use it to launch your app from another application.