简体   繁体   中英

android-app link not working

I'm following this example from Google I/O 2015.
Demo webite: http://recipe-app.com/recipe/grilled-potato-salad Demo app: http://search-codelabs.appspot.com/codelabs/android-deep-linking

My test:
I've installed the demo app from above link. I did a Google search using Google Search app for "grilled potato salad" and found http://recipe-app.com/recipe/grilled-potato-salad .
I would expect clicking on the link would open the app directly, not the disambiguation dialog ( http://search-codelabs.appspot.com/img/android-deep-linking/img-5.png ). However, the disambiguation dialog still shows to my surprise.

Isn't the <link rel="alternate" href="android-app://com.recipe_app/http/recipe-app.com/recipe/grilled-potato-salad" /> on the website useless then?

The app's manifest file:
```

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/CustomActionBarTheme" >

    <activity
        android:name=".client.HomeActivity"
        android:label="@string/app_name"
        android:exported="true"
        android:theme="@android:style/Theme.Holo.NoActionBar">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <activity
        android:name=".client.RecipeActivity"
        android:label="@string/app_name"
        android:exported="true"
        android:launchMode="singleTop"
        android:theme="@android:style/Theme.Holo.NoActionBar">
        <intent-filter android:label="@string/app_name">
            <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 "http://recipe-app.com/recipe" -->
            <data android:scheme="http"
                android:host="recipe-app.com"
                android:pathPrefix="/recipe" />
        </intent-filter>
    </activity>

    <provider
        android:name=".client.content_provider.RecipeContentProvider"
        android:authorities="com.recipe_app" >
    </provider>
</application>

```

That tutorial was indeed outdated.
The HTML markup was indeed useless.

What was required for Google search results to work with deep link is to have a publicly reabled https://<yoursite>/.well-known/assetlinks.json file on your production webserver following the instructions here :
After setting up URL support for your app, the App Links Assistant generates a Digital Asset Links file you can use to associate your website with your app.

As an alternative to using the Digital Asset Links file, you can associate your site and app in Search Console.

To associate your app and your website using the App Links Assistant, click Open the Digital Asset Links File Generator from the App Links Assistant and follow these steps:

The App Links Assistant walks you through basic URL mapping Figure 2. Enter details about your site and app to generate a Digital Asset Links file.

  1. Enter your Site domain and your Application ID. 2) To include support in your Digital Asset Links file for Smart Lock for Passwords, select Support sharing credentials between the app and the website and enter your site's login URL. This adds the following string to your Digital Asset Links file declaring that your app and website share sign-in credentials: delegate_permission/common.get_login_creds. Learn more about supporting Smart Lock for Passwords in your app. 3) Specify the signing config or select a keystore file. Make sure you select the right config or keystore file for either the release build or debug build of your app. If you want to set up your production build, use the release config. If you want to test your build, use the debug config. 4) Click Generate Digital Asset Links file. 5) Once Android Studio generates the file, click Save file to download it. 6) Upload the assetlinks.json file to your site, with read-access for everyone, at https:///.well-known/assetlinks.json. Important: The system verifies the Digital Asset Links file via the encrypted HTTPS protocol. Make sure that the assetlinks.json file is accessible over an HTTPS connection, regardless of whether your app's intent filter includes https.

  2. Click Link and Verify to confirm that you've uploaded the correct Digital Asset Links file to the correct location.

You should now be able to see Your app - Installed in Google search results, that's how you know that it has worked

Try using

<intent-filter tools:node="merge" android:autoVerify="true">

autoverify in the intent-filter tag tells Android to check that the website and the app have the same common owner which is must for app linking (Otherwise, it is just deep linking which is why you see the disambiguation dialogue).

<intent-filter android:label="@string/app_name" android:autoVerify="true" >
<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 "http://recipe-app.com/recipe" -->

<data android:scheme="http"
  android:host="recipe-app.com"
  android:pathPrefix="/recipe" />
</intent-filter>

Now, try opening the link first on the 'default browser' in your device, the default browser is usually the Google search. Sometimes, app link might not work in chrome or some other application for different reasons.

That you are already familiar with deep linking, you can also refer to this link https://developer.android.com/training/app-links/ for learning how to make your website url redirect to your app on users phone (If it is installed. If not, see 'Instant Apps-Android').

If you have successfully integrated all steps and your link is verified to be connected to your activity but still not triggering app's activity, then go to app's setting and enable deep linking then select your provided links. This will be auto enabled once you update your release build in play store.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM