我正在使用AccessibilityService来监视通知。我跟踪了这和这。最后,它起作用了,我开始了解新的通知。
但是,要实现AccessibilityService的连接,我需要要求用户从ACCESSIBILITY_SETTINGS,中启用它--我是这样做的:
Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);但是,问题是我想检查用户是否启用了它(AccessibilityService)。而且,如果用户已经启用了它,我也不会再要求他们启用它。那么,有可能做到这一点吗?
发布于 2015-11-19 15:14:00
您可以通过检查安全设置来测试用户是否启用了可访问性服务。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);https://stackoverflow.com/questions/27652026
复制相似问题