7

I'm using an Activity with an intent filter similar to the one described here to be able to intercept clicks in the browser and give the user the option to open the my app instead. Here's the code from my AndroidManifest.xml:

<activity android:name="com.scompt.ScomptIntentFilter"> <intent-filter> <data android:scheme="http" android:host="www.scompt.com" /> <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 isn't working if I enter http://www.scompt.com into the browser. The page is loaded, just like normal.

If I enter either of the following commands on the command line, then I'm given the standard chooser between my app and the browser, as I would expect.

adb -d shell am start -d http://www.scompt.com -a android.intent.action.VIEW adb -d shell am start -d http://www.scompt.com 

Is there any other place I should look to get this to work? I've verified what I'm doing with the open-source hubroid and I seem to be doing the same thing.

5
  • What kind of phone? What version of Android? On Ice Cream Sandwich on my phone and tablet, it appears that browsers no longer can launch intents like this... I have an xkcd app that worked this way before but no longer does on ICS. Commented May 29, 2012 at 13:11
  • @DrakeClarris It's a Galaxy S running 2.2. Also, the hubroid app mentioned in the question is doing what I want, so I don't think it's a phone/OS problem. Commented May 29, 2012 at 14:46
  • Did you ever get this resolved? I'm having this exact problem, and I am sure that my scheme and host are correct. The intent works when I run adb commands, but not when I click links matching the URL defined in the intent. Commented Sep 14, 2017 at 20:56
  • My problem was that my the links I was using to test were built on React and so Javascript was intercepting all the links and doing single page application navigation. Commented Sep 14, 2017 at 21:04
  • 1
    If Android 12 or higher, read stackoverflow.com/a/73743424/14784590 Commented Sep 16, 2022 at 10:27

4 Answers 4

12

With regards to intents there is a distinct difference between a user typing a URL into their browser and following a link in a web page, email etc.

An intent WILL be fired as you expect if you follow a link on a browser web page or a link in an email.

However, when the user types a URL into the address bar of their browser Android believes that the user specifically wants that URL to open in the browser and therefore does not fire an intent.

So if you want to test URLs and intent filters then you need to setup a static web page with hyperlinks on it or send an email to your phone.

When you think about it this system works in a similar fashion to the default browser behaviour in Windows. Imagine your default browser is Chrome but you also have Firefox installed. If you click a link in an email it will open in Chrome. If however you open Firefox and type a URL into the address bar and hit go it DOES NOT open in Chrome because clearly you want the URL to open in Firefox.

Sign up to request clarification or add additional context in comments.

3 Comments

Do you know how this works in regards to a webpage redirecting? Say if www.abc.com redirects to www.xyz.com, and my app can handle www.xyz.com, would I get the choice to use my app?
This should be the accepted answer! great insight there.
Typing your app url directly into the address bar (or through bookmark) doesn't always work anymore. But what you can do is type html and/or js directly into the address bar, like this: data:text/html,<body onload="window.location='myapp://';"> This triggers a redirect. If this doesn't work either you can type hyperlinks and click that: data:text/html,<h1><a href='myapp://'>myapp It should work without closing tags. You can bookmark these urls too!
3

http://example.com isn't http://www.example.com.

Try typing http://www.example.com into the browser and see if that works.

This is the manifest code that works for me:

<activity android:name="MY_APP" <intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <data android:host="MY_HOST" android:scheme="MY_SCHEME" /> </intent-filter> </activity> 

4 Comments

Good eye, @marmor. That was a typo when typing up the question. I've fixed it now.
try changing the scheme to something unique like scompt and type in the browser scompt://www.scompt.com. If that works the browser may not pop selectors for recognized types like http or https.
I've also tried a custom scheme without success. The browser is able to do what I want because it's doing so for the hubroid app, as mentioned in the question.
see if my edit helps... I seem to be using a different category then you
2

add pathPatterns to data tag:

 <data android:host="www.example.com" android:scheme="http" android:pathPattern=".*"> </data> <data android:host="example.com" android:scheme="http" android:pathPattern=".*"> </data> 

Comments

1

I had exactly the same problem as of 28 Jan 2014 with chrome browser. check my answer here

Launch custom android application from android browser

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.