I have an app that uses the accessibility services to listen to notifications. It works correctly unti the user reboots. If you reboot, you have to disable/re-enable the service from the accessibility services menu.
Why does the app not get the events after a 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 the 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 the 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 was facing same problem. After a lot of attempt I found that this problem occurs with older version of android (eg.Jellybean). when device is powered off the service gets unbinded. But it is not rebinded
on_Boot_Completed
. As this problem doesn't appear on newer version of android I considered it as a android bug. Because only way to re-activate the service is turning off and restarting the service, I am usingsharedPreference
to keep track states of my service. whenonUnbind
onRebind
oronServiceConnected
is called I update mysharedPreference
with the value I associated for it. Now, before using service I check that if the service calledonRebind
oronServiceConnected
if not then I tell user to restart service or start working with my service.If you are so confused then you can Include the bellow code in your accessibility service.
Then before start working with the service check if service is valid like bellow,