Android8.0中,应用程序被关闭后,无法再次获取无障碍服务权限的问题。
创始人
2024-10-01 16:00:12
0

可以使用以下代码解决此问题:

首先,在AndroidManifest.xml文件中添加以下权限:

然后,在应用程序中添加以下代码:

//检查应用程序是否有无障碍服务权限 public boolean isAccessibilityEnabled(Context context) { int accessibilityEnabled = 0; final String service = context.getPackageName() + "/" + AccessibilityServiceName.class.getCanonicalName(); try { accessibilityEnabled = Settings.Secure.getInt(context.getContentResolver(), android.provider.Settings.Secure.ACCESSIBILITY_ENABLED); Log.v(TAG, "accessibilityEnabled = " + accessibilityEnabled); } catch (Settings.SettingNotFoundException e) { Log.e(TAG, "Error finding setting, default accessibility to not found: " + e.getMessage()); } TextUtils.SimpleStringSplitter mStringColonSplitter = new TextUtils.SimpleStringSplitter(':');

if (accessibilityEnabled == ACCESSIBILITY_ENABLED) {
    Log.v(TAG, "***ACCESSIBILITY IS ENABLED*** -----------------");
    String settingValue = Settings.Secure.getString(context.getContentResolver(),
    Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);
    if (settingValue != null) {
        mStringColonSplitter.setString(settingValue);
        while (mStringColonSplitter.hasNext()) {
            String accessibilityService = mStringColonSplitter.next();

            Log.v(TAG, "-------------- > accessibilityService :: " + accessibilityService + " " + service);
            if (accessibilityService.equalsIgnoreCase(service)) {
                Log.v(TAG, "We've found the correct setting - accessibility is switched on!");
                return true;
            }
        }
    }
}
else {
    Log.v(TAG, "***ACCESSIBILITY IS DISABLED***");
}
return false;

}

//启用无障碍服务 private void enableAccessibilityService() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Intent settingsIntent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS); startActivity(settingsIntent); } else { Intent settingsIntent = new Intent(Settings.ACTION_SETTINGS); startActivity(settingsIntent); } }

//检查应用程序是否有适当

相关内容

热门资讯

六分钟了解!大菠萝免费辅助,w... 六分钟了解!大菠萝免费辅助,wepoker透视器免费,介绍教程(有挂神器);1分钟了解详细教程(微信...
今日百科!hhpoker到底可... 今日百科!hhpoker到底可以作弊吗,impoker辅助,详细教程(有挂攻略);大神普及一款德州a...
一分钟快速了解!xpoker辅... 一分钟快速了解!xpoker辅助怎么用,wepoker钻石怎么看底牌,详细教程(有挂技巧)准备好在w...
一分钟揭秘!wepoker数据... 一分钟揭秘!wepoker数据分析,德普之星透视辅助软件激活码,细节方法(有挂技巧);德普之星透视辅...
记者揭秘!wepoker私人局... 记者揭秘!wepoker私人局辅助器怎么用,wepoker手机插件,2025新版技巧(有挂技巧);建...
记者发布!如何下载wepoke... 记者发布!如何下载wepoker安装包,微扑克微乐辅助,黑科技教程(有挂攻略)关于如何下载wepok...
揭秘关于!agpoker辅助,... 1、揭秘关于!agpoker辅助,hhpoker必备开挂,新2025教程(有挂透明)。2、hhpok...
重大发现!aapoker破解侠... 重大发现!aapoker破解侠是真的吗,cloudpoker外挂,大神讲解(有挂神器)是由北京得aa...
必看攻略!wepoker怎么下... 必看攻略!wepoker怎么下载游戏,wepoker透视脚本免费下载,详细教程(有挂技巧);致您一封...
发现一款!德州局透视脚本,HH... 发现一款!德州局透视脚本,HH平台挂,扑克教程(有挂技巧)1、很好的工具软件,可以解锁游戏的ai质量...