Android Respond To URL in Intent
Asked Answered
M

2

156

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.

Miscellany answered 8/2, 2009 at 2:55 Comment(2)
There's a great answer to this question at #2448713Monde
There is a better answer to this question #1610073Byelection
M
195

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!

Miscellany answered 8/2, 2009 at 3:16 Comment(10)
It doesnt work for me. Can you please give an example-Link that would open the Application.Local
I'd like to react to "www.youtube.com" but NOT to "www.youtube.com/fr/"... Any idea how I can do that?Berk
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?Scorify
look #2959201Mullis
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!Lowman
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: https://mcmap.net/q/81883/-launching-custom-android-application-from-android-browser-chrome PS: struggled for days over this.Crossly
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.Sontich
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: <data android:pathPattern=".*"/>Trevethick
remember that you also need to add the intent filter to the actual activity which will handle the incoming requestGerminative
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 lollipopLiverwurst
A
14

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>
Aspirant answered 9/7, 2016 at 21:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.