隐藏应用程序窗口小部件根据API级别 [英] Hide app widget depending on API level

查看:168
本文介绍了隐藏应用程序窗口小部件根据API级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了三个应用程序部件具有不同的尺寸的Andr​​oid pre Honecomb版本和一个可调整大小的滚动的ListView控件的蜂窝和更高版本。

I've created three app widgets with different sizes for pre Honecomb versions of Android and one resizable scrollable listview widget for Honeycomb and later.

由于部件提供相同的功能和一个针对蜂窝,后来是可调整大小的,我想删除其他版本的插件对API级别12或更高版本。这可能不知?

Since the widgets offer the same functionality and the one targeted for Honeycomb and later is resizable I would like to remove the other versions of the widget on API level 12 or later. Is this possible somehow?

据我可以告诉似乎没有任何办法从得到登记的AppWidgetService如果能找到AppWidgetProviderInfo资源文件禁用窗口小部件。这样看来,我只能包含在更高版本的部件,但不排除在XML文件夹针对早期API版本中定义的版本。

As far as I can tell there doesn't seem to be any way to disable a widget from getting registered by the AppWidgetService if it can find the AppWidgetProviderInfo resource file. So it seems that I can only include widgets on later versions but not exclude versions defined in xml folders that targets earlier API versions.

推荐答案

如果它是一个单一的应用程序的小工具,有pre-HC或HC的实现,你可以将它们组合成一个 AppWidgetProvider 和使用 RES / XML-V11 / RES / XML / 有不同的元数据。

If it were a single app widget that had pre-HC or HC implementations, you could combine them into one AppWidgetProvider and use res/xml-v11/ and res/xml/ to have different metadata.

我能想到的来处理您的方案的唯一途径,不过,是为纪念某些 AppWidgetProviders 如清单(安卓禁用:启用=假),然后启用并在您的应用程序的基础上 android.os.Build.VERSION 第一次运行禁用提供商使用 PackageManager setComponentEnabledSetting(),给你正确的设置。由于在Android 3.1以上版本,用户将需要推出自己的活动之一,可以添加应用程序窗口小部件,无论如何,你至少可以在其中应用此逻辑的入口点。

The only way I can think of to handle your scenario, though, is to mark some of the AppWidgetProviders as disabled in the manifest (android:enabled="false"), then enable and disable your providers on the first run of your app based on android.os.Build.VERSION using PackageManager and setComponentEnabledSetting(), to give you the right set. Since on Android 3.1+, the user will need to launch one of your activities to be able to add the app widget, anyway, you at least have the entry point in which to apply this logic.

这篇关于隐藏应用程序窗口小部件根据API级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆