开启Android辅助功能 Accessibility Services

开启Android辅助功能 Accessibility Services

  • 在root模式下自动开启辅助服务,执行命令
settings put secure enabled_accessibility_services com.example.app/.ExampleService
settings put secure accessibility_enabled 1

但是,这样做其他已经开启的辅助服务会关闭,在/data/system/users/0/settings_secure.xml 目录下保存着所有已开启的Accessibility Services,因此要同时开启多个Accessibility Services可以加“:”做拼接

settings put secure enabled_accessibility_services com.example.app/.ExampleService1:com.example.app/.ExampleService2
settings put secure accessibility_enabled 1
  • 利用代码
//申请权限



//设置代码
fun startAccessServices(serviceName: String, callback: () -> Unit) {
Settings.Secure.putString(getContentResolver(),
Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "packageName/serviceName")
Settings.Secure.putString(getContentResolver(),
Settings.Secure.ACCESSIBILITY_ENABLED, "1")
}

你可能感兴趣的:(开启Android辅助功能 Accessibility Services)