Android Respond To URL in Intent

╄→гoц情女王★ 提交于 2019-11-26 01:21:54

问题


I want my intent to be launched when the user goes to a certain url: for example, the android market does this with http://market.android.com/ urls. so does youtube. I want mine to do that too.


回答1:


I did it! Using <intent-filter>. Put the following into your manifest file:

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

This works perfectly!




回答2:


You might need to add different permutations to your intent filter to get it to work in different cases (http/ https/ ect).

For example, I had to do the following for an app which would open when the user opened a link to google drive forms, www.docs.google.com/forms

Note that path prefix is 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>


来源:https://stackoverflow.com/questions/525063/android-respond-to-url-in-intent

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!