Android15默认开启无障碍服务
在wms、ams的systemReady()方法中调用此方法并传入要开启的无障碍服务即可实现自动开启
/*** 开启无障碍服务** @param context 上下文* @param accessibilityService com.pranavpandey.rotation/com.pranavpandey.rotation.service.RotationService*/private static void enableAccessibilityService(Context context, String accessibilityService) {// 添加默认开启Rotation[com.pranavpandey.rotation]_V28.3.2无障碍服务 add by lywif (Settings.Secure.getInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 0) == 0) {Settings.Secure.putInt(context.getContentResolver(), Settings.Secure.ACCESSIBILITY_ENABLED, 1);Log.e(TAG, "----liyiwei---- 打开无障碍服务功能,写入1");} else {Log.e(TAG, "----liyiwei---- 无障碍服务功能已打开");}String currentServices = Settings.Secure.getString(context.getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES);Log.e(TAG, "----liyiwei---- 当前开启的无障碍服务有: 【" + currentServices + "】");if (currentServices == null || currentServices.isEmpty()) {Settings.Secure.putString(context.getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,accessibilityService);Log.e(TAG, "----liyiwei---- 写入无障碍服务成功 不存在已有服务,直接写入:" + accessibilityService);} else {if (currentServices.contains(accessibilityService)) {Log.e(TAG, "----liyiwei---- 无障碍服务列表已包含,无须重复开启:" + currentServices);} else {Settings.Secure.putString(context.getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES,currentServices + ":" + accessibilityService);Log.e(TAG, "----liyiwei---- 写入无障碍服务成功 存在服务,追加写入:" + accessibilityService);}}}
如果上面的东西对你有用,可否打赏一杯奶茶给在下