Android 在应用程序强制停止后手动重新启用时,辅助功能服务不会重新启动
我遇到了一个问题,我的辅助功能服务在应用程序被强制停止然后再次手动打开后没有重新启动,这会重新启动其他常规服务。可访问性服务在手动重新启用(预期)、禁用和第二次重新启用之前不会启动并再次工作。不幸的是,在非库存安卓系统中内置的任务杀手中,应用程序被杀死的情况非常普遍 摘要:Android 在应用程序强制停止后手动重新启用时,辅助功能服务不会重新启动,android,service,accessibility,accessibilityservice,Android,Service,Accessibility,Accessibilityservice,我遇到了一个问题,我的辅助功能服务在应用程序被强制停止然后再次手动打开后没有重新启动,这会重新启动其他常规服务。可访问性服务在手动重新启用(预期)、禁用和第二次重新启用之前不会启动并再次工作。不幸的是,在非库存安卓系统中内置的任务杀手中,应用程序被杀死的情况非常普遍 摘要: 强制停止应用程序将禁用辅助功能服务。这是意料之中的。我可以检测到,每当下次手动打开应用程序时,辅助功能服务将不再启用,代码如下: public static boolean isAccessibilityServiceEna
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;
}
disableSelf();
我能够可靠启动AccessibilityService(无需a)的唯一方法是通过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
但这似乎是一个系统问题。您是否提出了一个?我也有同样的问题,有时第二次启用仍然不起作用。我发现:这个:-您使用哪个版本的TB和Android进行测试?谢谢您的回答。嗯,我需要它在客户端电话上可靠地运行,所以不幸的是,adb不是一个好的解决方案。我可以像过去一样,在问题跟踪器上提出一个问题,多年来什么事情都不会发生,直到他们将其标记为“过时”,并要求我重新记录。没用。@Flyview是的,它们确实需要很长时间。我注意到这是一个4年前的问题。你有问题追踪器的链接吗?可访问性团队(不是开发人员)相当友好
#!/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