有选择地针对某些API级别禁用Android服务 [英] Selectively disable an Android service for certain API levels

查看:91
本文介绍了有选择地针对某些API级别禁用Android服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android应用程序支持API 8+,但是解析库似乎在少于10个的API上完全崩溃了(甚至在10个上也有些许破坏).我知道如何在某些API级别上禁用 code 块,但是是否可以仅针对API 11+选择性地启用在AndroidManifest.xml中声明的<service>? (它也可以通过BOOT_COMPLETE <intent>启动,也需要将其禁用)

My Android app supports API 8+, however the Parse library seems to break completely on APIs less than 10 (and even a little bit on 10 too). I know how to disable blocks of code on certain API levels, but is there a way that a <service> declared in AndroidManifest.xml can be selectively enabled only for API 11+? (it also gets started up by the BOOT_COMPLETE <intent> which would also need to be disabled)

推荐答案

步骤1:创建一个名为i_can_haz_parsebool资源的res/values/bools.xml文件,并将其设置为false

Step #1: Create a res/values/bools.xml file, with a bool resource named i_can_haz_parse, set to false

步骤2:创建一个res/values-v11/bools.xml文件,并使用一个名为i_can_haz_parsebool资源,并将其设置为true

Step #2: Create a res/values-v11/bools.xml file, with a bool resource also named i_can_haz_parse, set to true

步骤3:仅在API级别11+上对组件(如您的服务)使用android:enabled="@bool/i_can_haz_parse"

Step #3: Have android:enabled="@bool/i_can_haz_parse" on the components, like your service, that you want only on API Level 11+

这篇关于有选择地针对某些API级别禁用Android服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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