Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intent-filter not working from browser

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.

like image 727
Edward Dale Avatar asked May 29 '12 12:05

Edward Dale


2 Answers

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.

like image 77
Oliver Pearmain Avatar answered Oct 25 '22 17:10

Oliver Pearmain


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>
like image 32
marmor Avatar answered Oct 25 '22 17:10

marmor