0

我正在使用AccessibilityService来监控通知。我跟着这个这个。最后,它起作用了,我开始了解新的通知。

但是,要连接AccessibilityService,我需要让用户从ACCESSIBILITY_SETTINGS启用它,我是这样做的:

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);

但是,问题是我想检查用户是否启用了它(AccessibilityService)。另外,如果他们已经启用它,我不会再要求用户启用它。那么,有可能做到这一点吗?

4

1 回答 1

1

您可以通过检查安全设置来测试用户是否启用了您的辅助功能服务。Settings.Secure.getString()会给你一个:单独的启用服务列表,你可以检查你的服务是否在那里。像这样的东西:

ComponentName compName = new ComponentName(context, MyAccessibilityService.class);
String flatName = compName.flattenToString();
String enabledList = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
boolean isEnabled = enabledList != null && enabledList.contains(flatName);
于 2015-11-19T15:14:00.123 回答