Android以Intent响应URL

我希望我的意图,当用户去一个特定的url推出:例如,Android市场这样做http://market.android.com/url。 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> 

这完美的作品!

您可能需要为您的意图filter添加不同的排列,以使其在不同情况下(http / https / ect)起作用。

例如,我必须为用户打开链接到Google驱动器表单时打开的应用程序执行以下操作: www.docs.google.com/forms

请注意,path前缀是可选的。

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