简体   繁体   English

Android 应用链接无效

[英]Android app links not working

I am trying to get App Links working on my Android app but am unable to figure out why it doesn't work.我正在尝试让应用程序链接在我的 Android 应用程序上运行,但无法弄清楚为什么它不起作用。

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

In MyActivity.java I have: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
    }
}

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://www.mywebsite.com/.well-known/assetlinks.json显示得很好

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以下验证链接也会检查: https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite.com&relation=delegate_permission/common.handle_all_urls : https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite.com&relation=delegate_permission/common.handle_all_urls : https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite.com&relation=delegate_permission/common.handle_all_urls : https://digitalassetlinks.googleapis.com/v1/statements:list?source.web.site=https://www.mywebsite.com&relation=delegate_permission/common.handle_all_urls

I have installed a signed apk on an actual device running Android 7.0.我已经在运行 Android 7.0 的实际设备上安装了一个签名的 apk。 Upon installation, I can see in the logs of my web server that the device successfully obtains the assetlinks.json file.安装后,我可以在我的 Web 服务器的日志中看到设备成功获取了 assetlinks.json 文件。

As a result, running adb shell dumpsys package d shows the following:因此,运行adb shell dumpsys package d显示以下内容:

App linkages for user 0:

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

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.我向自己发送了一封电子邮件,链接为https://www.mywebsite.com/foo/bar ,它只是打开了应用程序选择器对话框,甚至没有建议我的应用程序。 It only shows browser options.它只显示浏览器选项。

Clicking a link such as maps.google.com does open the Maps app directly.单击诸如maps.google.com的链接会直接打开地图应用程序。 Which leads me to think the problem doesn't have anything to do with the phone's settings.这让我认为问题与手机的设置无关。

What am I missing?我错过了什么?

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.根据Android Studio 提供的“工具”选项卡下的“应用链接助手”工具,托管assetlinks.json 文件后,您需要在strings.xml 文件中添加资产语句列表,然后将其链接到清单文件。

Check following steps -检查以下步骤 -

  1. Add Asset Statement to strings.xml将资产声明添加到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>
  2. Link strings to AndroidManifest.xml将字符串链接到 AndroidManifest.xml

     <meta-data android:name="asset_statements" android:resource="@string/asset_statements" />
  3. Add autoVerify to intent filter element.将 autoVerify 添加到意图过滤器元素。

I had also wasted too much time in understanding this process.我也浪费了太多时间来理解这个过程。

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

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