如何在应用程序启动后立即为我的应用程序启用辅助功能设置

Kes*_*234 2 android android-permissions accessibilityservice

我正在尝试在应用程序启动后立即为我的应用程序启用辅助功能设置。但我目前无法做到。我使用了以下代码:

 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, 
                           "package_name");
 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ACCESSIBILITY_ENABLED, 
                           "1");
Run Code Online (Sandbox Code Playgroud)

要使用此代码片段,我们必须声明以下权限:

WRITE_SECURE_SETTINGS,但此权限仅适用于系统应用程序。如何为我的应用程序实现相同的功能。欢迎提出所有建议。

ser*_*inc 7

API 说:Settings.Secure

对于用户必须通过系统 UI或这些值的专用 API显式修改的首选项,而不是由应用程序直接修改。

如果您想以编程方式检查以提示用户,另请参阅android-how-do-you-check-if-a-particular-accessibilityservice-is-enabled。例如在how-to-programmatically-enable-disable-accessibility-service-in-android 中给出了调用意图的代码,它是

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);
Run Code Online (Sandbox Code Playgroud)