Search code examples
androidgoogle-chromefirefoxintentfilter

Open App from URL works on Firefox for Android but not on Google Chrome


I want to open my Android app when user taps on link to my webpage (preferably from Facebook share post, but let's start with plain URL).

To achieve this, I've created an Activity UrlReceiver and added this code to my AndroidManifest.xml file (URLs are just for testing purpose):

<activity
        android:name=".main.core.UrlReceiver"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.VIEW"/>
            <category android:name="android.intent.category.DEFAULT"/>
            <category android:name="android.intent.category.BROWSABLE"/>

            <data
                android:host="martinfowler.com"
                android:pathPrefix="/"
                android:scheme="http"/>
            <data
                android:host="www.martinfowler.com"
                android:pathPrefix="/"
                android:scheme="http"/>
            <data
                android:host="test"
                android:scheme="myapp"/>
        </intent-filter>
</activity>

And this is working on Firefox for Android, when I enter myapp://test/ it opens my app automatically, when I enter martinfowler.com there is an Android head next to the url which leads on tap to my app. And this is fine.

But it is not working on Google Chrome. When I enter myapp://test/ it starts Google searching and when I enter martinfowler.com it just opens the webpage.

I started digging about this on the web and found this document: https://developer.chrome.com/multidevice/android/intents, exmplaining that custom schemas won't work in Chrome anymore so I tried using this URLs (according to the document):

intent://test/#Intent;scheme=myapp;package=com.my.app;end
intent://#Intent;scheme=myapp;package=com.my.app;end
intent://test/#Intent;package=com.my.app;scheme=myapp;end
intent://#Intent;package=com.my.app;scheme=myapp;end

But these are starting Google search as well. What can I do, to open my App from URL in Google Chrome?

I've tested this on both KitKat and Lolipop.


Solution

  • The problem was that I had been typing (or copying) the URLs into Chrome Omnibox (search bar) and according to this issue: https://code.google.com/p/chromium/issues/detail?id=451956 it's no longer supported:

    In http://crbug.com/331571 we decided not to start an Intent if the original navigation is started from a user's typing because we thought that generally a user wouldn't expect to leave Chrome when typing a URL into the omnibox.

    So opening the app from the URL in Google Chrome works only on link tap, and doesn't work when using the search bar.