I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want mine to do that too.
-
8There's a great answer to this question at stackoverflow.com/questions/2448213/… – neu242 Jun 24 '10 at 6:11
-
2There is a better answer to this question stackoverflow.com/questions/1609573/… – rds Sep 16 '12 at 15:05
I did it! Using <intent-filter>. Put the following into your manifest file:
<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="www.youtube.com" android:scheme="http" />
</intent-filter>
This works perfectly!
-
9It doesnt work for me. Can you please give an example-Link that would open the Application. – Pascal Klein Apr 1 '11 at 14:39
-
7I'd like to react to "www.youtube.com" but NOT to "www.youtube.com/fr/"... Any idea how I can do that? – Gilbou Oct 28 '11 at 16:10
-
5
-
1Not sure how this is working for the entire world. Just doesn't work on chrome and it always opens the link in browser until you place the "android:pathPrefix" element. The answer anyways doesn't have the category values as mentioned in the documentation. If it still doesn't work for someone, refer this please: stackoverflow.com/a/21727055/2695276 PS: struggled for days over this. – Rajat Sharma Jan 2 '15 at 21:08
-
1It is important to know that this only work if you open the link OUTSIDE of a browser , from the notes app, or a message from whatsapp, It is working on lollipop – D4rWiNS May 17 '16 at 12:21
You might need to allow different combinations of data in your intent filter to get it to work in different cases (http/ vs https/, www. vs no www., etc).
For example, I had to do the following for an app which would open when the user opened a link to Google Drive forms (www.docs.google.com/forms)
Note that path prefix is optional.
<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:scheme="http" />
<data android:scheme="https" />
<data android:host="www.docs.google.com" />
<data android:host="docs.google.com" />
<data android:pathPrefix="/forms" />
</intent-filter>