6

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?

mickael
  • 315
  • 4
  • 9
  • Search for `SingleHostAsyncVerifier` in the logcat during app install. What are the logs? – Simon Marquis Oct 31 '17 at 16:08
  • 2
    If everything looks fine, try to remove/simplify the `pathPattern` attribute as it might not recognize such regexp characters: https://developer.android.com/guide/topics/manifest/data-element.html – Simon Marquis Oct 31 '17 at 16:10
  • @SimonMarquis `SingleHostAsyncVerifier` returns `-> true` for my website. – mickael Nov 01 '17 at 16:24
  • @SimonMarquis your second comment was spot on. Everything worked perfectly after simplifying the pattern with `.*` notations. After digging deeper, it turns out `pathPattern` uses the `PatternMatcher` and not traditional regex. Thanks! – mickael Nov 01 '17 at 19:45

1 Answers1

0

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.

Akash Bisariya
  • 3,855
  • 2
  • 30
  • 42