我正在遵循google i/o 2015中的这个示例。
演示网站:http://recipe-app.com/recipe/grilled-potato-salad
演示应用程序:http://search-codelabs.appspot.com/codelabs/android-deep-linking
我的测试:
我已经从上面的链接安装了演示应用程序。
我使用谷歌搜索应用程序对“烤土豆沙拉”进行了谷歌搜索,结果发现http://recipe-app.com/recipe/grilled-potato-salad
我希望点击链接可以直接打开应用程序,而不是消歧对话框(http://search-codelabs.appspot.com/img/android-deep-linking/img-5.png)。
然而,消歧对话框仍然让我惊讶。
那么网站上的<link rel="alternate" href="android-app://com.recipe_app/http/recipe-app.com/recipe/grilled-potato-salad" />不是没用吗?
应用程序的清单文件:
` `

<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>

` `

最佳答案

试用使用

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

intent filter标签中的autoverify告诉android检查网站和应用程序是否具有相同的公共所有者,这是应用程序链接所必须的(否则,这只是深度链接,这就是为什么您会看到消歧对话框)。
<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>

现在,试着先打开设备中“默认浏览器”上的链接,默认浏览器通常是google搜索。有时,由于不同的原因,app link可能无法在chrome或其他应用程序中工作。
如果您已经熟悉深度链接,您还可以参考此链接https://developer.android.com/training/app-links/了解如何使您的网站url重定向到用户电话上的应用程序(如果已安装)。如果没有,请参阅“即时应用Android”)。

07-24 09:45
查看更多