Android BROWSABLE intent API level

本小妞迷上赌 提交于 2019-12-04 05:05:28

问题


Are there different steps to register an Android Activity as a BROWSABLE intent on Android 2.3 (API level 10) and earlier versions?

I've set up an Activity with an intent filter that uses a custom scheme:

<intent-filter>
    <action name="android.intent.action.VIEW"/>
    <category name="android.intent.category.DEFAULT"/>
    <category name="android.intent.category.BROWSABLE"/>
    <data scheme="@string/myCallbackProtocol"/>
</intent-filter>

On a physical device running 2.3, and with the SDK's simulator set to 2.3, the browser application directs links using my custom protocol to the app.

However, if I scale back the simulator to 2.2 or 2.1 then the browser does not redirect but instead indicates the server cannot be found. I don't have an actual device running these API levels.

I would like to release my app so it's compatible with devices running 2.1 and greater. Am I wrong to assume this should be possible? According to the Android docs Intent.CATEGORY_BROWSABLE has been available since 1.0.

Thanks!


回答1:


I have had no problems using BROWSABLE going back at least to 2.1 if not earlier. However, I have not implemented a custom scheme, let alone one defined in a string resource. Here is a sample project demonstrating the use of BROWSABLE.




回答2:


Solved. BROWSABLE works back at least as far as Android 2.1. Before 2.3 it seems that loading the <data scheme=""> from a string resource leads to the Activity not being registered correctly.

Changing the @string/ reference to a hard-coded value yields the desired result.

<intent-filter>
    <action name="android.intent.action.VIEW"/>
    <category name="android.intent.category.DEFAULT"/>
    <category name="android.intent.category.BROWSABLE"/>
    <data scheme="my-custom-protocol"/>
</intent-filter>


来源:https://stackoverflow.com/questions/6049290/android-browsable-intent-api-level

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