简体   繁体   English

android-app链接不起作用

[英]android-app link not working

I'm following this example from Google I/O 2015.我正在关注 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演示网站: http://recipe-app.com/recipe/grilled-potato-salad演示应用: 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 .我使用谷歌搜索应用程序对“烤土豆沙拉”进行了谷歌搜索,发现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 ).我希望单击链接会直接打开应用程序,而不是消歧对话框( 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?那网站上的<link rel="alternate" href="android-app://com.recipe_app/http/recipe-app.com/recipe/grilled-potato-salad" />不是没用吗?

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. HTML 标记确实没用。

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 : Google 搜索结果与深层链接一起使用所需要的是按照此处的说明在您的生产网络服务器上有一个公开的https://<yoursite>/.well-known/assetlinks.json文件:
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.为您的应用程序设置 URL 支持后,应用程序链接助手会生成一个数字资产链接文件,您可以使用它来将您的网站与您的应用程序相关联。

As an alternative to using the Digital Asset Links file, you can associate your site and app in Search Console.作为使用数字资产链接文件的替代方法,您可以在 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:要使用 App Links Assistant 关联您的 App 和您的网站,请单击 App Links Assistant 中的 Open the Digital Asset Links File Generator,然后按照以下步骤操作:

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. App Links Assistant 将引导您完成基本的 URL 映射 图 2. 输入有关您的站点和应用程序的详细信息以生成数字资产链接文件。

  1. Enter your Site domain and your Application ID.输入您的站点域和您的应用程序 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. 2) 要在您的数字资产链接文件中包含对密码 Smart Lock 的支持,请选择支持在应用程序和网站之间共享凭据并输入您网站的登录 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.这会将以下字符串添加到您的数字资产链接文件,声明您的应用程序和网站共享登录凭据:delegate_permission/common.get_login_creds。 Learn more about supporting Smart Lock for Passwords in your app.详细了解如何在您的应用中支持 Smart Lock for Passwords。 3) Specify the signing config or select a keystore file. 3) 指定签名配置或选择一个密钥库文件。 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. 4) 单击生成数字资产链接文件。 5) Once Android Studio generates the file, click Save file to download it. 5) Android Studio 生成文件后,单击“保存文件”进行下载。 6) Upload the assetlinks.json file to your site, with read-access for everyone, at https:///.well-known/assetlinks.json. 6) 将 assetlinks.json 文件上传到您的站点,每个人都具有读取权限,位于 https:///.well-known/assetlinks.json。 Important: The system verifies the Digital Asset Links file via the encrypted HTTPS protocol.重要提示:系统通过加密的 HTTPS 协议验证数字资产链接文件。 Make sure that the assetlinks.json file is accessible over an HTTPS connection, regardless of whether your app's intent filter includes https.确保 assetlinks.json 文件可通过 HTTPS 连接访问,无论您的应用程序的 Intent 过滤器是否包含 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您现在应该能够看到您的应用 -已安装在 Google 搜索结果中,这就是您知道它已运行的方式

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 标签中的 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>

Now, try opening the link first on the 'default browser' in your device, the default browser is usually the Google search.现在,尝试先在您设备的“默认浏览器”上打开链接,默认浏览器通常是 Google 搜索。 Sometimes, app link might not work in chrome or some other application for different reasons.有时,由于不同的原因,应用程序链接可能无法在 Chrome 或其他一些应用程序中使用。

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').如果您已经熟悉深度链接,您还可以参考此链接https://developer.android.com/training/app-links/了解如何让您的网站 url 重定向到用户手机上的应用程序(如果它已安装。如果没有,请参阅“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.如果您已成功集成所有步骤并且您的链接已验证连接到您的活动但仍未触发应用程序的活动,则 go 到应用程序的设置并启用深度链接,然后 select 您提供的链接。 This will be auto enabled once you update your release build in play store.一旦您在 Play 商店中更新发布版本,这将自动启用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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