java - AccessibilityService stops receiving events on reboot -
i have app uses accessibility services listen notifications. works correctly unti user reboots. if reboot, have disable/re-enable service accessibility services menu.
why app not events after reboot?
@override protected void onserviceconnected() { pman = new preferencesmanager(this); bulbmanager = new bulbmanager(((context) this), pman.getbridge()); accessibilityserviceinfo info = new accessibilityserviceinfo(); info.eventtypes = accessibilityevent.type_notification_state_changed; info.notificationtimeout = 100; info.feedbacktype = accessibilityevent.types_all_mask; setserviceinfo(info); log.d("omg, started finally!", "right now!"); }
and xml
<accessibility-service xmlns:android="http://schemas.android.com/apk/res/android" android:accessibilityeventtypes="typenotificationstatechanged" android:packagenames="com.t3hh4xx0r.huenotifier" android:accessibilityfeedbacktype="feedbackallmask" android:notificationtimeout="100" android:accessibilityflags="flagdefault" android:settingsactivity="com.t3hh4xx0r.huenotifier.activities.loadingsplashactivity" android:canretrievewindowcontent="false" android:description="@string/app_name" />
and manifest
<service android:name="com.t3hh4xx0r.huenotifier.myaccessibilityservice" 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/service_info" /> </service>
i facing same problem. after lot of attempt found problem occurs older version of android (eg.jellybean). when device powered off service gets unbinded. not rebinded on_boot_completed
. problem doesn't appear on newer version of android considered android bug. because way re-activate service turning off , restarting service, using sharedpreference
keep track states of service. when onunbind
onrebind
or onserviceconnected
called update sharedpreference
value associated it. now, before using service check if service called onrebind
or onserviceconnected
if not tell user restart service or start working service.
if confused can include bellow code in accessibility service.
public static string accessibilitypreference="accessibilitypreference"; public static string isservicebinded="isservicebinded"; @override public void onserviceconnected() { log.e(tag, "acc::onserviceconnected:************************* "); sharedpreferences p=getsharedpreferences(accessibilitypreference,context.mode_private); sharedpreferences.editor e=p.edit(); e.putboolean(isservicebinded,true); e.commit(); } @override public boolean onunbind(intent intent) { log.e("onunbind","onunbind called***************************************************"); sharedpreferences p=getsharedpreferences(accessibilitypreference,context.mode_private); sharedpreferences.editor e=p.edit(); e.putboolean(isservicebinded,false); e.commit(); return super.onunbind(intent); } @override public void onrebind(intent intent) { log.e("onrebind","onrebind called***************************************************"); sharedpreferences p=getsharedpreferences(accessibilitypreference,context.mode_private); sharedpreferences.editor e=p.edit(); e.putboolean(isservicebinded,true); e.commit(); super.onrebind(intent); } public static boolean isservicebinded(sharedpreferences preferences){ return preferences.getboolean(isservicebinded,true); }
then before start working service check if service valid bellow,
if(accessibilityworkservice.isservicebinded(getsharedpreferences(accessibilityworkservice.accessibilitypreference, context.mode_private))){ //start working }else { //tell user restart service }
Comments
Post a Comment