Android在Intent中响应URL

Isa*_*ler 151 url android launch intentfilter android-intent

我希望在用户访问某个网址时启动我的意图:例如,Android市场通过http://market.android.com/网址进行此操作.youtube也是如此.我也希望我也这样做.

Isa*_*ler 190

我做的!用<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>
Run Code Online (Sandbox Code Playgroud)

这很完美!

  • 它对我不起作用.你能举个例子 - 可以打开应用程序的链接吗? (8认同)
  • 我想对"www.youtube.com"作出反应,但不要对"www.youtube.com/fr /"做出反应......任何想法我怎么能这样做? (7认同)
  • 这不适用于Android Lollipop:/ (7认同)
  • 看http://stackoverflow.com/questions/2958701/launch-custom-android-application-from-android-browser (5认同)
  • 重要的是要知道,只有当您在浏览器外部、从笔记应用程序或来自 Whatsapp 的消息打开链接时,这才有效,它适用于棒棒糖 (2认同)

Jor*_*aud 9

您可能需要向intent过滤器添加不同的排列,以使其在不同的情况下工作(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>
Run Code Online (Sandbox Code Playgroud)