Methods to Upload Deep Hyperlinks in Jetpack Compose?

This is a part of the Jetpack Compose navigation sequence:

A deep hyperlink is a link that takes you at once to a definite display in your app.

As an example, clicking on my weblog’s URL, the Android OS presentations a listing of apps that can be utilized to open the URL as you’ll see beneath.

Word: The UI above would possibly glance a little bit other on other Android OS

Since my weblog’s app helps deep hyperlinks, it presentations up as probably the most apps, the primary one from the left. If I open it with my weblog’s app, it takes me to specify display content material inside of my app. That is the referred to as deep hyperlink.

To exhibit how you can put in force the deep hyperlink, I exploit this easy Jetpack Compose navigation for example. Let’s upload the deep hyperlink.

Assessment

The instance app has 4 monitors:

  • Login Display

  • House Display

  • Profile Display

  • Seek Display

I’ll upload the deep hyperlink for every display on this instance app.

1. Upload hostname within the job’s intent filter out

In AndroidManifest.xml, upload the <information>, <class> and <motion> tags within the job’s intent filter out as proven beneath.

<manifest xmlns:android="http://schemas.android.com/apk/res/android">
...
    <job
        ...
        <intent-filter>
            <information android:host="vinchamp77.github.io"
                android:scheme="https" />
            <class android:identify="android.intent.class.DEFAULT" />
            <class android:identify="android.intent.class.BROWSABLE" />
            <motion android:identify="android.intent.motion.VIEW" />
        </intent-filter>

    </job>
...
</manifest>

Word: Hostname is case-sensitive and must be lowercase characters.

The next code in NavGraph.kt must be up to date via including the deepLinks parameter when calling the NavGraphBuilder.composable().


navGraphBuilder.composable(
    direction = NavRoute.Login.trail,
    deepLinks = listOf (
        navDeepLink {
            uriPattern = "https://vinchamp77.github.io/deeplink/login"
            motion = Intent.ACTION_VIEW
        }
    ),
) {
    
}


navGraphBuilder.composable(
    direction = NavRoute.House.trail,
    deepLinks = listOf (
        navDeepLink {
            uriPattern = "https://vinchamp77.github.io/deeplink/house"
            motion = Intent.ACTION_VIEW
        }
    ),
) {
    
}


navGraphBuilder.composable(
    direction = NavRoute.Profile.withArgsFormat(NavRoute.Profile.identification, NavRoute.Profile.showDetails),
    deepLinks = listOf (
        navDeepLink {
            uriPattern = "https://vinchamp77.github.io/deeplink/profile?identification={identification}&showDetails={showDetails}"
            motion = Intent.ACTION_VIEW
        }
    ),
    
) {
    

}


navGraphBuilder.composable(
    direction = NavRoute.Seek.withArgsFormat(NavRoute.Seek.question),
    deepLinks = listOf (
        navDeepLink {
            uriPattern = "https://vinchamp77.github.io/deeplink/seek?question={question}"
            motion = Intent.ACTION_VIEW
        }
    ),
    
) {
    
}

You construct the record of NavDeepLink the usage of navDeepLink() helper serve as via specifying the uriPattern and the motion parameters.

URI trend with none argument is easy, no large deal. Then again, when the URI trend has arguments, it will have to observe the same old URL question parameters structure.

It took me some time to determine this out. As an example, the next URI trend may not paintings.

 uriPattern = "https://vinchamp77.github.io/deeplink/seek/{question}"

It really works best if in case you have one deep hyperlink outlined. If there’s multiple deep hyperlink, it falls again to the primary deep hyperlink that you just outlined.

So it will have to be on this structure.

uriPattern = "https://vinchamp77.github.io/deeplink/seek?question={question}"

The best way to check the deep hyperlink is to make use of the Equipment -> App LInks Assistant in Android Studio.

Cross to step 4 – Take a look at on software or emulator at once.

Then, upload the URL that you just wish to take a look at and click on Run Take a look at.

Word: Those are similar adb instructions.

$ adb shell setprop log.tag.AppIndexApi VERBOSE
$ adb shell am get started -a android.intent.motion.VIEW -c android.intent.class.BROWSABLE -d 'https://vinchamp77.github.io/deeplink/seek?question="liang moi"'

Click on JUST ONCE or ALWAYS to open with Easy Navigation Compose App.

The quest display is proven with the hunt question that we handed in from the URL.

You are no longer finished! Deep hyperlinks are in spite of everything carried out to your app.

Neatly, no longer in point of fact. If you happen to run this app on Android 12 (API stage 31). The hyperlink does not take you to the app in any respect. It calls for you to make sure the deep hyperlinks’ hostname belongs for your app.

To try this, you first want to generate a Virtual Asset Hyperlinks report and add it for your as specify location in your web site.

  • <your hostname>/.well-know/assetlinks.json

Now, continue to step 3 – Affiliate web site within the App Hyperlinks Assistant

Numerous information will have to be already pre-filled for you. Choose Signing config -> Debug, and click on Generate Virtual Asset Hyperlinks Record.

For a manufacturing construct, make a choice Choose keystore report as a substitute

As soon as the report is generated, you’ll click on Save report to obtain the report. You want to replicate the report for your web site. On this instance, the report location is

In case you are the usage of a <username>.github.io web page like mine, there are a few things you wish to have to concentrate on for the .well known folder to be known.

Manner 1 – If you happen to have _config.yml, you wish to have so as to add the come with: [“.well-known”]. That is an instance of my github web page’s _config.yml.

theme: jekyll-theme-minimal
name: Vincent Tsen
description: Self-taught Hobbyist Local Android Kotlin Developer
come with: [".well-known"]

Manner 2 – If you happen to do not have _config.yml, you upload .nojekyll on your root listing**.** The .nojekyII is solely an empty report with none content material.

Click on Hyperlink and Examine and also you will have to see

Luck! Your app is related to the chosen area(s).

The Android Studio additionally routinely added the autoVerify to the intent filter out parts.

<intent-filter android:autoVerify="true">
    <information android:host="vinchamp77.github.io"
        android:scheme="https" />
    <class android:identify="android.intent.class.DEFAULT" />
    <class android:identify="android.intent.class.BROWSABLE" />
    <motion android:identify="android.intent.motion.VIEW" />
</intent-filter>

Attempt to take a look at the app hyperlink in step 3 above on Android 12 (API stage 31) and above, it really works!

You may additionally realize that it does not suggested you to choose between a listing of apps, however as a substitute takes you at once for your app. This may be the good thing about verifying your hostname.

Abstract

Deep hyperlink is slightly helpful as it brings you at once to a particular display. Something I spotted is that if the URL does not fit any of the URL patterns, it falls again to the primary deep hyperlink. As an example, the primary deep hyperlink on this instance is the login display. The entire invalid URL brings you to the login display at once.

As opposed to triggering a deep hyperlink from URL, you’ll additionally cause the deep hyperlink from any other app the usage of PendingIntent. I can quilt the PendingIntent subject in a while. Experience!

Supply Code

GitHub Repository: Demo_SimpleNavigationCompose (deep hyperlink department)

You May Also Like

More From Author

+ There are no comments

Add yours