Frage

Ich möchte, dass meine Absicht ins Leben gerufen werden, wenn der Benutzer auf eine bestimmte URL geht: zum Beispiel der Android Market tut dies mit http://market.android.com/ Urls. so tut youtube. Ich will mein das auch tun.

War es hilfreich?

Lösung

Ich habe es geschafft! Mit <intent-filter> . Legen Sie die folgenden in Ihrer Manifest-Datei:

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

Das funktioniert perfekt!

Andere Tipps

Sie können verschiedene Permutationen Ihre Absicht Filter hinzufügen müssen, um es in verschiedenen Fällen zu arbeiten (http / https / ect).

Zum Beispiel hatte ich die folgenden für eine App zu tun, die sich öffnen würde, wenn der Benutzer auf einen Link geöffnet Antriebsformen Google, www.docs.google.com/forms

Beachten Sie, dass Pfadpräfix ist 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>
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top