Back

Deep Linking: Uniting Your Android App and Website for Seamless Navigation

Last updated on 25 Mar, 2023

Deep linking is a powerful feature in mobile app development that allows users to seamlessly navigate from external sources to specific content within an app. In this article, we'll cover what deep linking is, how it works in Android, and how to deep link HTTPS website links into your Android app.

What is Deep Linking?

Deep linking is the practice of linking to a specific piece of content within an app, rather than just launching the app itself. This allows users to directly access a specific feature or screen within an app, without having to navigate through menus and screens to get there.

Deep linking can be used for a variety of purposes, such as linking to specific products within an e-commerce app, linking to specific articles within a news app, or linking to specific locations within a maps app. It can also be used for marketing and user acquisition purposes, by allowing developers to link directly to their app from external sources such as social media or websites.

How Does Deep Linking Work in Android?

In Android, deep linking is implemented using an intent filter in the app's manifest file. The intent filter specifies the URI scheme and host that the app should respond to when a user clicks on a deep link.

Here's an example of an intent filter for a deep link that launches a specific activity within an app:


      <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="myapp" android:host="myapp.com" android:path="/product/123" />
      </intent-filter>
      

In this example, the intent filter specifies that the app should respond to deep links with the URI scheme "myapp", the host "myapp.com", and the path "/product/123". When a user clicks on a deep link with this URI, the Android operating system will check if any apps on the device are registered to handle this URI scheme and host, and if so, will launch the app and pass the relevant information to it.

How to Deep Link HTTPS Website Links into Your Android App

Now that you understand how deep linking works in Android, let's take a look at how to deep link HTTPS website links into your app. Here's a step-by-step instruction:

Step 1: Add the Intent Filter to Your Manifest File

First, you'll need to add an intent filter to your app's manifest file to specify the URI scheme and host that the app should respond to when a user clicks on a deep link. Here's an example intent filter:


      <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="https" android:host="www.example.com" />
      </intent-filter>
      

In this example, the intent filter specifies that the app should respond to deep links with the HTTPS scheme and the host "www.example.com". Note that we've also included the "android:autoVerify" attribute, which tells the Android operating system to verify that the app owns the domain specified in the intent filter. This is important for security reasons and to ensure that the deep links are handled correctly.

Step 2: Handle the Deep Link in Your Activity

Once you've added the intent filter to your manifest file, you'll need to handle the deep link in your activity. In React Native, you can do this by checking the intent data in your functional component's useEffect hook.

Here's an example of how to handle a deep link in a React Native functional component:


      import { useEffect } from 'react';
      import { Linking } from 'react-native';
      
      function MyScreen() {
        useEffect(() => {
          const handleDeepLink = async () => {
            const url = await Linking.getInitialURL();
            if (url) {
              // Handle the deep link
            }
          };
          handleDeepLink();
          Linking.addEventListener('url', handleDeepLink);
          return () => {
            Linking.removeEventListener('url', handleDeepLink);
          };
        }, []);
      
        return (
          // Render your screen content here
        );
      }
      

In this example, we're using the useEffect hook to set up the deep link handling logic. The handleDeepLink function is called when the component mounts and adds an event listener for the "url" event. When the user clicks on a deep link and the app is opened, the Linking.getInitialURL() method returns the deep link URL, and we can then handle the deep link accordingly.

Note that we're also adding a cleanup function in the useEffect hook to remove the event listener when the component unmounts. This is important to avoid memory leaks and ensure that the deep link handling works correctly.

Step 3: Test the Deep Linking Functionality

Once you've added the intent filter to your manifest file and set up the deep link handling logic in your activity, you can test the deep linking functionality by clicking on a deep link from an external source, such as a website or social media app.

When you click on a deep link, the Android operating system should open your app and pass the relevant information to it. You can then use this information to navigate to the appropriate screen or feature within your app.

Steps to grab the assetlinks.json file from the Google Play Console and verify the domain authority:

1. Go to the Google Play Console and select your app.
2. Click on "Release" in the left-hand menu and select "Setup" under "App Integrity".
3. Click on "App Signing" tab.
4. Go to "Digital Asset Links JSON" section, copy json and paste it into new file named "assetlinks.json".
5. To verify the domain authority, the assetlinks.json file should be placed in the ".well-known" directory on the root of your domain. For example, if your domain is "example.com", the file should be placed at "https://example.com/.well-known/assetlinks.json".

Refer screenshot below



Steps to verify if the assetlinks.json file is configured properly via the latest Google Play Console:

1. Go to the Google Play Console and select your app.
2. Click on "Grow" in the left-hand menu and select "User Acquisition".
3. Click on "Deep links" in the sub-menu.
4. Scroll down to the "Web URL Verification" section and click on the domain name that you want to verify.
5. In the "Domain details" section, click on the "Verify" button.
6. Google will check the configuration of your assetlinks.json file and display the verification status. If the verification is successful, you will see a message saying "Verified". If there is an issue with the configuration, you will see an error message indicating what went wrong.

Refer screenshot below to open deeplinks screen



Refer screenshot below to verify your domain



Conclusion

Deep linking is a powerful feature in mobile app development that allows users to seamlessly navigate from external sources to specific content within an app. In Android, deep linking is implemented using an intent filter in the app's manifest file, and can be handled in your app's activity or screen.

In this article, we've covered how to deep link HTTPS website links into your Android app using React Native, including the necessary intent filter configuration and deep link handling code. By following these steps, you can provide a seamless user experience and increase engagement with your app.

about author

Hitesh Agja

My name is Hitesh Agja, and I have over 12 years of experience in the industry. I am constantly driven by my excitement and passion for learning new things, whether they are technical or not. I believe that life is all about continuous learning and progress, and I strive to bring that mindset to everything I do.

Let's talkhire -button