Android可访问性服务向后兼容和Jelly Bean [英] Android accessibility service backwards compatibility and jelly bean

查看:86
本文介绍了Android可访问性服务向后兼容和Jelly Bean的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用可访问性服务监视事件的应用程序.在ICS之前的Android版本中,它总是可以正常工作,但是有了Jelly bean,我的运气就不那么好了.

I've got an app that uses the accessibility service to monitor for events. It's always worked fine in versions of android up to ICS, but with Jelly bean I'm not having much luck.

正如文件所述,我已经添加

As the documents mention I've added

android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE"

到清单文件中的我的服务.这将使应用程序使用xml的声明性xml方法正常运行.

to my service in the manifest file. This causes the app to work fine using the declarative xml method for the xml.

问题在于向后兼容.对于姜饼等版本,我现在遇到以下错误:

The problem is on backwards compatibility. For versions such as gingerbread I'm now getting the following error:

07-15 22:15:56.090: E/ACRA(1168): Caused by: java.lang.SecurityException: Not allowed to start service Intent { cmp=com.example/.MainRunningService (has extras) } without permission android.permission.BIND_ACCESSIBILITY_SERVICE

我已更新到兼容性jar的最新版本,希望可能会有所帮助,但仍然会收到错误消息.

I've updated to the latest revision of the compatibility jar hoping that may help, but still get the error.

我不确定如何获得旧版本和新版本之间的兼容性.

I'm not sure how I get compatibility between older and newer versions.

如果我从清单中删除了BIND_ACCESSIBILITY_SERVICE,则我的应用不会显示在Jelly Bean中,因此无法打开辅助功能.有什么建议吗?

If I remove the BIND_ACCESSIBILITY_SERVICE from the manifest, then my app doesn't show in Jelly Bean to be able to switch accessibility on. Any suggestions?

推荐答案

好的,马克·墨菲(Mark murphy)向我提出了一些建议,这是可行的.

ok, mark murphy suggested a few bits to me and this is what worked.

对服务类进行子类化,因此有2个版本.

Subclass the service class so there are 2 versions of it.

然后在res/values目录中有一个bools.xml文件,在res/values-v16目录中也有一个

Then have a bools.xml file in the res/values directory and also one in the res/values-v16 directory

在v16中将is_jelly_bean布尔值设置为true,并在res/values目录中将is_not_jelly_bean设置为.

Have a is_jelly_bean boolean set to true in v16 and a is_not_jelly_bean in the res/values directory.

然后清单中有类似的内容

Then in the manifest have something like this

<service android:name=".service.MainRunningService" android:enabled="@bool/is_jelly_bean"
             android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE">
        <intent-filter >
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>

        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibilityservice" />
    </service>



    <service android:name=".service.MainRunningServicePreJellyBean" 
             android:enabled="@bool/is_not_jelly_bean">
        <intent-filter >
            <action android:name="android.accessibilityservice.AccessibilityService" />
        </intent-filter>

        <meta-data
            android:name="android.accessibilityservice"
            android:resource="@xml/accessibilityservice" />
    </service>

这篇关于Android可访问性服务向后兼容和Jelly Bean的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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