在应用程序被强制停止然后再次手动打开后,我的辅助功能服务没有重新启动,这确实会重新启动其他常规服务。无障碍服务在手动重新启用(预期)、禁用和重新启用之前不会启动并再次工作第二次。 不幸的是,应用程序被杀死现在在非库存 Android 中内置的任务杀手中很常见。
摘要:
public static boolean isAccessibilityServiceEnabled(Context context) {
String prefString = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
return prefString != null && prefString.contains(context.getPackageName());
}
public static boolean isServiceRunning(Context context, Class targetService) {
List<ActivityManager.RunningServiceInfo> serviceInfos = getRunningServices(context);
String targetServiceName = targetService.getName();
for (ActivityManager.RunningServiceInfo serviceInfo : serviceInfos) {
if(serviceInfo.service.getClassName().equals(targetServiceName)) {
return true;
}
}
return false;
}
context.startService(new Intent(context, MyAccessibilityService.class));
disableSelf();
总之,用户认为他们已经重新启用了该服务,但它不起作用。重新启动设备或禁用服务并再次启用它确实可以解决它。
有谁知道如何解决这个问题?当应用程序被强制停止时服务被禁用已经够糟糕了,但更糟糕的是即使用户手动重新启用它也不会启动。
这是在 Android 11 上测试的。
类似的问题:
How to check if accessibility service crashed (Android Pie now displays this info in settings)?
Restart Accessibility Service After Crash
最佳答案
我能够可靠地启动我的 AccessibilityService(没有 shortcut assigned )的唯一方法是通过 ADB:
#!/bin/sh
VALUE_OFF="com.android.talkback/com.google.android.marvin.talkback.TalkBackService"
TALKBACK="com.google.android.marvin.talkback/com.google.android.marvin.talkback.TalkBackService"
ALLYSERVICE="[myservicename]"
VALUE_ON="$TALKBACK:$ALLYSERVICE"
if [ "$ENABLE" = true ]; then
adb shell settings put secure enabled_accessibility_services $VALUE_ON
adb shell settings put secure accessibility_enabled 1
else
adb shell settings put secure enabled_accessibility_services $VALUE_OFF
adb shell settings put secure accessibility_enabled 0
fi
但这似乎是一个系统的事情。您是否提出了 issue on the issue tracker ?
关于android - 应用强制停止后手动重新启用辅助功能服务不会重新启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67410929/