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

I want to open my Android application when a user clicks on a link to my web page (preferably from a post on Facebook, but let it start with a simple URL).

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

 <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 it works on Firefox for Android , when I log in to myapp://test/ , it automatically opens my application, when I log in to martinfowler.com , there is an Android head next to the URL that leads to my app on the tap. And that is wonderful.

But Google Chrome does not work. When I enter myapp://test/ , it starts a Google search, and when I enter martinfowler.com , it just opens a web page.

I started digging into this on the Internet and found this document: https://developer.chrome.com/multidevice/android/intents explaining that custom schemes will no longer work in Chrome, so I tried using these URLs (according with 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 they also start a Google search. What to do to open an application from a URL in Google Chrome?

I tested this on both KitKat and Lolipop.

+6
source share
1 answer

The problem was that I was typing (or copying ) URLs in Chrome Omnibox (search bar) and according to this problem: https://code.google.com/p/chromium/issues/detail?id= 451956 it is no longer supported:

At http://crbug.com/331571 we decided not to start the intention if the original navigation starts with user input, because we thought that usually the user would not expect to exit Chrome when entering the URL in the omnibox.

Thus, opening an application from a URL in Google Chrome only works when a link is clicked and does not work when using the search bar.

+5
source

Source: https://habr.com/ru/post/984889/


All Articles