Question

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.

Was it helpful?

Solution

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!

OTHER TIPS

You might need to add different permutations to your intent filter to get it to work in different cases (http/ https/ ect).

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"
                android:host="docs.google.com"
                android:pathPrefix="/forms"/>
            <data
                android:scheme="http"
                android:host="www.docs.google.com"
                android:pathPrefix="/forms" />

            <data
                android:scheme="https"
                android:host="www.docs.google.com"
                android:pathPrefix="/forms" />

            <data
                android:scheme="https"
                android:host="docs.google.com"
                android:pathPrefix="/forms" />
        </intent-filter>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top