155

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.

Rahul Tiwari
  • 5,931
  • 2
  • 41
  • 66
Isaac Waller
  • 32,041
  • 27
  • 93
  • 107
  • 8
    There's a great answer to this question at http://stackoverflow.com/questions/2448213/how-to-implement-my-very-own-uri-schema-on-android/2448531#2448531 – neu242 Jun 24 '10 at 06:11
  • 2
    There is a better answer to this question http://stackoverflow.com/questions/1609573/intercepting-links-from-the-browser-to-open-my-android-app – rds Sep 16 '12 at 15:05

2 Answers2

193

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!

tomrozb
  • 23,522
  • 30
  • 89
  • 110
Isaac Waller
  • 32,041
  • 27
  • 93
  • 107
  • 9
    It doesnt work for me. Can you please give an example-Link that would open the Application. – Pascal Klein Apr 01 '11 at 14:39
  • 7
    I'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
  • This works perfectly, thanks, but i also need to obtain the URL that was clicked to open the app. anyone can explain how to do this? – boogieman May 17 '12 at 12:59
  • 5
    look http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser – J-Rou May 31 '12 at 18:42
  • This was the only thing that worked properly for me after browsing around for a long time, trying those random schemes such as "myapp://" but not being able to properly test them (or wasn't told how to test them). Put the above in, fire up the browser, search Youtube on Google, and any link will allow me to use my application to open it! – Gary Feb 26 '14 at 18:46
  • 1
    Not 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: http://stackoverflow.com/a/21727055/2695276 PS: struggled for days over this. – Rajat Sharma Jan 02 '15 at 21:08
  • My problem is my link from email, or anyother resource needs to open first in browser then it redirected to the desired link, any solution how can i get that redirected app and open my application. – arslan haktic Feb 04 '15 at 12:54
  • If you have problems with this solution is maybe because your final URL starts with the `host` pattern but is not exactly that. If this is the case, try adding: `` – lgvalle Aug 26 '15 at 12:20
  • remember that you also need to add the intent filter to the actual activity which will handle the incoming request – Aiden Strydom Nov 06 '15 at 07:18
  • 1
    It 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
11

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>
gardenapple
  • 35
  • 10
Jordan Réjaud
  • 425
  • 8
  • 13