繁体   English   中英

对Activity的最低SDK版本支持

[英]Minimum SDK version support for Activity

该应用程序有一些活动,有些只在更高版本上运行。 但由于活动支持intent-filter mimeType ,所以我无法控制它的启动。

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />

            <category android:name="android.intent.category.DEFAULT" />

            <data android:mimeType="image/*" />
        </intent-filter>

就像具有此intent-filter的活动可以通过降低版本而不是必须启动。 例如:活动必须在版本11及更高版本中运行,但android仍然会在较低版本的图像选择器对话框中显示它。 有没有办法避免这种情况?

您必须使用intent-filter进行“控制器”活动。

当此活动开始时,它将检查当前的SDK级别,然后将Intent转发到较低或较高的SDK活动,然后是finish()本身。

在您的情况下,这可以为您提供进一步的灵活性,比如说您希望将平板电脑定位到第三项活动。


另一个论点可能是你的Activity应该测试SDK级别,然后根据这个来交换Fragments 即您的Activity与SDK无关,但它是一个控制器,用于显示正确的片段。

参考文献:

http://developer.android.com/training/basics/supporting-devices/platforms.html http://developer.android.com/training/basics/supporting-devices/platforms.html#version-codes

http://developer.android.com/training/backward-compatible-ui/abstracting.html

http://developer.android.com/training/backward-compatible-ui/using-component.html

正如您从参考文献中看到的那样,您应该阅读培训文档

如果你只是在寻找XML配置,我可以建议你如何在Android API演示中完成它。

他们将AndroidManifest中的Activity声明为禁用或启用,具体取决于API版本,如android:enabled="@bool/atLeastHoneycomb" ,其中@bool/atLeastHoneycomb只是一个在values-v11 @bool/atLeastHoneycomb中设置为true且在false中设置为false的标志默认values文件夹(您可以查看Android API演示,如前所述,了解更多详情)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM