Question

Je veux que mon intention d'être lancé lorsque l'utilisateur passe à une certaine URL: par exemple, le marché Android avec ce fait http://market.android.com/ urls. il en va de youtube. Je veux moi à le faire aussi.

Était-ce utile?

La solution

Je l'ai fait! En utilisant <intent-filter> . Il faut mettre dans votre fichier manifeste:

<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>

Cela fonctionne parfaitement!

Autres conseils

Vous devrez peut-être ajouter différentes permutations à votre filtre l'intention de le faire fonctionner dans différents cas (http / https / ect).

Par exemple, je devais faire ce qui suit pour une application qui ouvrirait lorsque l'utilisateur ouvre un lien vers Google formulaires de commande, www.docs.google.com/forms

Notez que le préfixe de chemin est facultative.

        <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>
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top