我有一个使用无障碍服务来收听通知的应用程序。它可以正常工作,直到用户重新启动。如果您重新启动,您必须从无障碍服务菜单中禁用/重新启用该服务。
为什么应用程序在重新启动后无法获取事件?
@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!");
}
和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" />
和清单
<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>