且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式启用/禁用 Android 设备上的辅助功能设置

更新时间:2023-01-23 15:48:08

只有系统应用才能以编程方式启用/禁用无障碍服务.系统应用可以直接写入设置安全数据库启动无障碍服务.

Only system apps can enable/disable accessibility service programatically. System apps can directly write in settings secure db to start accessibility service.

Settings.Secure.putString(getContentResolver(),Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, "com.packagename/com.packagename.componentname");

在设置安全数据库中写入需要以下权限:

Following permission is required to write in settings secure db:

<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />

对于非系统应用,启动无障碍服务的唯一方法是通过意图将它们引导至无障碍设置屏幕并让用户手动启动服务:

For non system apps, only way to start accessibility service is direct them to accessibility settings screen via intent and let user manually start the service :

Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);