Android应用程式连结无法运作 [英] Android app links not working

查看:76
本文介绍了Android应用程式连结无法运作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使App Links在我的Android应用程序上正常工作,但无法弄清为什么它不起作用。

I am trying to get App Links working on my Android app but am unable to figure out why it doesn't work.

我添加了以下意图-将标签过滤到我的清单文件中:

I have added the following intent-filter tag to my Manifest file:

<activity android:name=".MyActivity">
  <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.mywebsite.com"
        android:pathPattern="(/[a-z]{2}|)/foo/bar" />
  </intent-filter>
<activity android:name=".MyActivity">

MyActivity.java 中,我有:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ...
    handleIntent(getIntent());
}

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    handleIntent(intent);
}

private void handleIntent(Intent intent){
    String appLinkAction = intent.getAction();
    Uri appLinkData = intent.getData();
    if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null){
        //Do something here
    }
}

我也将自动生成的数字资产链接文件添加到了我的网站。在 https://www.mywebsite.com/.well-known/assetlinks.json

I have also added the auto-generated digital asset links file to my website. It shows up just fine at https://www.mywebsite.com/.well-known/assetlinks.json

以下验证链接也会检出:
https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite .com& relation = delegate_permission / common.handle_all_urls

The following verification link checks out as well: https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite.com&relation=delegate_permission/common.handle_all_urls

我已在运行Android 7.0的实际设备上安装了签名的apk。
安装后,我可以在Web服务器的日志中看到设备成功获取了assetlinks.json文件。

I have installed a signed apk on an actual device running Android 7.0. Upon installation, I can see in the logs of my web server that the device successfully obtains the assetlinks.json file.

因此,运行 adb shell dumpsys软件包d 显示以下内容:

As a result, running adb shell dumpsys package d shows the following:

App linkages for user 0:

Package: com.myapp.myapp
Domains: www.mywebsite.com
Status:  always : 20000001f

我给自己发送了一封电子邮件,其链接为 https://www.mywebsite.com/foo/bar ,它只是打开应用选择器对话框,甚至没有建议我的应用。它仅显示浏览器选项。

I sent an email to myself with the link https://www.mywebsite.com/foo/bar and it just opens the app chooser dialog without even suggesting my app. It only shows browser options.

单击诸如 maps.google.com 之类的链接不会直接打开地图应用。这使我认为问题与手机的设置无关。

Clicking a link such as maps.google.com does open the Maps app directly. Which leads me to think the problem doesn't have anything to do with the phone's settings.

我缺少什么?

推荐答案

根据Android Studio中工具标签下提供的应用链接助手工具,在托管assetlinks.json文件之后,您需要在string.xml中添加资产报表列表文件,然后将其链接到清单文件。

According to "App Link Assistant" tool provided in Android Studio under "Tools" tab, after hosting the assetlinks.json file you need to add asset statement list in strings.xml file and then linked it to the manifest file.

检查以下步骤-


  1. 将资产报表添加到strings.xml

  1. Add Asset Statement to strings.xml

<string name="asset_statements">[{\n  \"relation\": [\"delegate_permission/common.handle_all_urls\"],\n  \"target\": {\n    \"namespace\": \"web\",\n    \"site\": \"https://bigakash.000webhostapp.com\",\n  }\n}]</string>


  • 将字符串链接到AndroidManifest.xml

  • Link strings to AndroidManifest.xml

    <meta-data
        android:name="asset_statements"
        android:resource="@string/asset_statements" />
    


  • 将自动验证添加到意图过滤器元素。

  • Add autoVerify to intent filter element.

    我也浪费了太多时间来理解此过程。

    I had also wasted too much time in understanding this process.

    这篇关于Android应用程式连结无法运作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆