5

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.

Community
  • 1
  • 1
Edward Dale
  • 28,070
  • 11
  • 84
  • 128
  • 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. – Drake Clarris May 29 '12 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. – Edward Dale May 29 '12 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`. – ckeeney Sep 14 '17 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. – ckeeney Sep 14 '17 at 21:04

4 Answers4

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.

Oliver Pearmain
  • 17,376
  • 12
  • 77
  • 83
2

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>
ckeeney
  • 1,014
  • 11
  • 16
marmor
  • 25,207
  • 10
  • 99
  • 145
  • Good eye, @marmor. That was a typo when typing up the question. I've fixed it now. – Edward Dale May 29 '12 at 12:34
  • 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. – marmor May 29 '12 at 12:46
  • 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. – Edward Dale May 29 '12 at 14:48
  • see if my edit helps... I seem to be using a different category then you – marmor May 29 '12 at 14:52
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

Community
  • 1
  • 1
AndroidGecko
  • 13,296
  • 3
  • 31
  • 47
1

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>