Android app links not working

*爱你&永不变心* 提交于 2019-12-14 01:25:21

问题


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

In MyActivity.java I have:

@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

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

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.

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

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.

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.

What am I missing?


回答1:


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.

Check following steps -

  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>
    
  2. Link strings to AndroidManifest.xml

    <meta-data
        android:name="asset_statements"
        android:resource="@string/asset_statements" />
    
  3. Add autoVerify to intent filter element.

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



来源:https://stackoverflow.com/questions/47022273/android-app-links-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!