6

I know there are several questions on SO about this, but none of them are helping to resolve my issue.

I want to be able to click a link from an email/text/browser and open my app.

I have the AndroidManifest.xml code:

    <!-- Splash Activity -->
    <activity
        android:name=".ui.SplashActivity"
        android:label="@string/app_name"
        android:theme="@style/SplashTheme"
        android:launchMode="singleTask">

        <!-- Launcher intent filter -->
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

        <!-- Branch URI scheme -->
        <intent-filter>
            <data android:scheme="myscheme" android:host="open" />
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
        </intent-filter>
    </activity>

This appears to follow the documentation here exactly, however, when I use Chrome (or Android Browser) to browse to myscheme://open, my app does not open, and instead I get Google search results for myscheme://open.

Can anyone see what piece of the puzzle I am missing here? How can I get my app to open via URI?

Small update:

After reading this, I have found that navigating Chrome to market://details?id=com.myapp does not open the play store. Instead it returns Google search results - the same as when trying to launch my app directly. Which is confusing. Am I missing a global OS setting to allow deep linking?

Community
  • 1
  • 1
Brett
  • 11,637
  • 34
  • 127
  • 213
  • "when I use Chrome (or Android Browser) to browse to myscheme://open" -- how **exactly** do you do this? Type that in the address bar? Click on a link in a Web page with that URL? Something else? – CommonsWare Mar 16 '17 at 17:21
  • @CommonsWare By (1) typing into the address bar, and (b) clicking a link in an email. Both result in the same behavior. – Brett Mar 16 '17 at 17:22

2 Answers2

5

Chrome does not open apps from manually-entered URI schemes. In fact, a manually-entered link will never launch an external app in Chrome. This is by design — for whatever reason, the Chrome team feels users should always be kept inside the browser after entering an address.

You can work around this to some extent by putting the deep link behind a user-drive action (a standard <a> tag, for example), but the Chrome has its own standard called Chrome Intents that you are supposed to use instead. Depending on the device you are using, this could also be the case for the standard browser.

In other apps, it's up to the app in question whether a custom URI scheme is identified as a 'clickable link'. For best compatibility, you'll want to wrap it inside a regular http:// link with a redirect.

If you're interested in an in-depth explanation of the complications around deep linking, this post is a good place to start. If you just want it to work without a lot of extra effort, Branch.io (full disclosure: I'm on the Branch team) solves this problem as a free service.

Alex Bauer
  • 13,147
  • 1
  • 27
  • 44
1

There is no requirement for any app to pay any attention to myscheme://open.

In particular:

  • There is no requirement for any Web browser to try to launch some third-party app when you type myscheme://open into the address bar, because users are unlikely to do that in the real world.

  • There is no requirement for an email program to try to create an ACTION_VIEW Intent for myscheme://open.

  • There is no requirement for an SMS client to search all incoming messages for the string myscheme://open, realize that this is somehow an app link, and do something with it.

You will have somewhat better luck overall using an https (or, in a pinch, http) URL as your app link (the http://www.example.com/gizmos URL from the documentation that you linked to). Then, SMS clients might recognize that this is a URL and do something with it. And, overall, you should be taken either to your app or to your Web page, both of which are at least somewhat useful to the user. However, your app still will not necessarily open when the user types your URL into the address bar, as browsers may not expect an app link to be entered there.

You can increase the odds of an https app link working, and working the way that you want, by publishing a digital asset links file and tying that into your manifest.

However, overall, this is still reliant on clients opting into paying attention to this stuff. Sometimes they will, because Android makes it relatively easy to do so. Sometimes they will not. A Web browser is welcome to see your URL, see that it is https, say "hey, as a Web browser, I know how to handle this!", and go load that Web page, ignoring your installed app. You and I might consider that to be a bug in that browser; the developers of that browser are welcome to disagree.

I have found that navigating Chrome to market://details?id=com.myapp does not open the play store

This goes back to the "developers can do what they want" part. If you clicked a link in a Web page to that URL, there is a chance that Chrome will take you to the Play Store. However, Chrome is not obligated to treat the address bar the same as it treats a link in a Web page.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491