Create deep link in Android app fast 2023

Learn to create deep link in Android app, after Android has updated the conditions for it. Now you need to prove that you own this website by publishing a assetlinks.json file in it.

What is Deep link?

– It is a link which resolves in an activity of your app. As the user taps on the link, activity of your App will be launched.

To start adding deep link in Android app go to the Tools menu and then App Links Assistant

Create deep link in Android app
Create deep link in Android app

After this click on open URL mapping editor

url mapping android studio
url mapping android studio

Create an Activity

Create an Activity which you want to open when clicked on the deep link.

Click on + icon, to add new URL mapping

Add URL mapping Android studio
Add URL mapping Android studio

In Host– add URL of your website

In Path– add a path string

Click on Add Logic to handle the intent [in the assistant window]

To create a deep link create and intent filter in an activity which you want to be launched, make the following changes in AndroidManifest.xml

        <activity android:name=".DeepLinkActivity"
            android:exported="true">
            <intent-filter>
                <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.codewithmakarand.com"
                    android:path="/mypath"/>
                <!-- note: the leading "/" is required for pathPrefix-->
            </intent-filter>
        </activity>

The resulting URL is formed as {scheme}://{host}{pathPrefix}

Here it will be http://www.codewithmakarand.com/mypath

Action VIEW is required so that the intern filter will be reachable from Google search

Category DEFAULT is required to start activity from implicit intents. Without it your activity will only be started from explicit intents [by specifying the complete path of your activity]

Category BROWSABLE is required as the link will be accessed from the browser, so without this if the user Clicks on the link it will not resolve into launching your activity

Make sure you add android:exported=”true” in your DeepLinkActivity’s tag in AndroidManifest.xml

Click on Open digital asset links file generator [in the assistant window] – let the default options be selected and click on Generate digital asset links file button

Add URL mapping Android studio
Add URL mapping Android studio
Preview of assetlinks.json file

Here the file will be generated and its path will be shown like this.

https://codewithmakarand.com/.well-known/assetlinks.json

Here dot .well-known is a folder in your root directory, where you have to put assetlinks.json file

For me it looks like this:

assetlinks.json file in folder

After that you can click on link and verify. It will verify if you have placed the file at correct place.

When it is verified you can run this app in your emulator and in the messaging app you can send a message with this link[in WhatsApp or any Messaging app]

https://codewithmakarand.com/mypath

If you click on this link your app will open. Now you have learned how to create deep link in Android app:)

Read more from here-

Android document

Leave a Comment