我要发动我的意图,当用户进入某个网址:例如,Android Market的这是否符合 http://market.android.com/ 网址。这样做的YouTube。我想我的做了。

有帮助吗?

解决方案

我做到了!使用 <intent-filter> 。把下面的内容清单文件:

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

这完美的作品!

其他提示

您可能需要不同的排列添加到您的意图过滤得到它在不同的情况下工作(HTTP / HTTPS / ECT)。

例如,我不得不做以下对一个应用程序时,用户打开一个链接,将打开到google驱动形式,www.docs.google.com/forms

请注意路径前缀是可选的。

        <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>
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top