On Sun, Jul 15, 2012 at 6:51 PM, Andy dev <andrewpmo...@gmail.com> wrote:
> I've got an app in the market which uses the accessibility service. For it
> to work correctly in Jelly bean I need to add the
> android.permission.BIND_ACCESSIBILITY_SERVICE permission to the service
> declaration in the android manifest file.
>
> Doing this is fine and gets things working for jelly bean, but then going
> back to my gingerbread Nexus One, it ends up crashing with 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
>
> I can't think how to get around this. Any suggestions. I would have thought
> it would have got silently ignored in older builds.

Hmmm...

The key will be using versioned resource sets (e.g., res/values/ and
res/values-v16/) to have different options for the different API
levels.

One approach you can try would be to set up a string resource with
regular and -v16 values. The -v16 value would be
android.permission.BIND_ACCESSIBILITY_SERVICE. The regular one would
either be the empty string (if that works) or some permission that the
system does hold and works. It's entirely possible that you will have
some difficulty finding such a permission, and I have never tried
using the empty string here.

Another alternative would be to set up a pair of boolean resources
(bools.xml). One, is_jelly_bean, would be set to true in -v16 and
false in the default set. The other, is_not_jelly_bean, would be set
to false in -v16 and true in the default set. Then, have two <service>
elements in the manifest. One would have your
android:permission="android.permission.BIND_ACCESSIBILITY_SERVICE" and
android:enabled="@bool/is_jelly_bean". The other <service> would not
have your android:permission attribute and would have
android:enabled="@bool/is_not_jelly_bean". Both would point to the
same AccessibilityService implementation if possible, or else one
points to a subclass of your existing AccessibilityService (if Android
yelps about two <service> elements for the same component).

With respect to the backwards compatibility, that would not be
possible in this case. However, it would have been nice if they would
have documented what to do better.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_The Busy Coder's Guide to Android Development_ Version 3.8 Available!

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to