First of all, my question is extremely similar to this, this and this. The Android documentation for what I'm trying to achieve is here. I couldn't get this to work using these resources so please don't mark this as duplicate as it is not.
I have a website and an Android application. The user will be able to scan QR codes that contain links like http://mywebsite.com/map/. When the user tries to open this link, I want Android to show him a chooser dialog where he can choose to open that link using my application. If my application is not installed, it should proceed to the specified website.
I know Chrome allows this by opening the chooser dialog when the user navigates to that address. For example, try downloading the Stack Exchange app and going to this question in Chrome. It will show this:
I have added the following code in AndroidManifest.xml after following the suggestion in the above-mentioned answers:
<intent-filter> <action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="mywebsite.com" android:path="/map" android:scheme="http" /> <data android:host="mywebsite.com" android:path="/animals" android:scheme="http" /> <data android:host="mywebsite.com" android:path="/articles" android:scheme="http" /> </intent-filter>
Also, I have tried adding android:mimeType="text/plain" to data but it didn't help.
The problem is that when I go to http://mywebsite.com/map or http://mywebsite.com/map/ Chrome just opens the webpage without showing the chooser dialog.
I would like to mention:
Simply sign-up for free -> upload the APK file -> choose the desired Android device-> run APK file directly in the browser. No complex setup or configurations.
You need to set it up like this :
<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="example.com" android:pathPrefix="/someresource/" android:scheme="http" /> <data android:host="www.example.com" android:pathPrefix="/someresource/" android:scheme="http" /> </intent-filter>
Notice that in your case, you would need to use android:pathPrefix instead of android:path.
Just to be sure, you should reset the preferences for your app in case you have accidentally set it to always open the link in chrome rather than show the chooser dialog. Once "Always" is used to open the matching uri, it will never show the chooser.
Second, you can have as many data elements in the intent filter as your want, but it is not necessary to repeat information. You can do the same thing like this:
<data android:host="mywebsite.com"/> <data android:scheme="http"/> <data android:path="/map"/> <data android:path="/animals"/> <data android:path="/articles"/>
But note that for the path, you can just use a wildcard
<data android:path="/.*"/>
Consider adding an additional
<data android:host="www.mywebsite.com"/>
And finally you may not want to show the chooser dialog but open a specific app intent/activity directly. On your website, if you detect the android user agent, you can create a link url this way:
<a href="intent://mywebsite.com/articles#Intent;package=com.myapp;scheme=http;end;"/>
See here for more details How do I open any app from my web browser (Chrome) in Android? What do I have to do with the A Href link?
Note that with this method if the app is not installed the user will be taken to the Google Play store for the specified app package.
If you are still having problems, check your intent filter priority. http://developer.android.com/guide/topics/manifest/intent-filter-element.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With