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

标签 android android-permissions accessibilityservice

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

 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ENABLED_ACCESSIBILITY_SERVICES, 
                           "package_name");
 Settings.Secure.putString(getContentResolver(), 
                           Settings.Secure.ACCESSIBILITY_ENABLED, 
                           "1");

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

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

最佳答案

API 表示:Settings.Secure

for preferences that the user must explicitly modify through the system UI or specialized APIs for those values, not modified directly by applications.

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

Intent intent = new Intent(android.provider.Settings.ACTION_ACCESSIBILITY_SETTINGS);
startActivityForResult(intent, 0);

关于android - 如何在应用程序启动后立即为我的应用程序启用辅助功能设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32010220/

相关文章:

android - 查询正在使用QUERY_ALL_PACKAGES权限的Android开发者

java - event.getSource 在辅助功能服务中返回 null。 (捕获第 3 方应用程序的源)

java - AccessibilityEvent.getPackageName() 返回 null

android - 如何在 Android 内置的 alertdialog 中设置 onclick

android - 安全异常 : Permission Denial: While launching Activity via explicit intent

android - 如何在 Android.mk 文件中构建 .s (asm) 文件

安卓权限拒绝 : forceStopPackage()

android - Accessibility Dialog/DialogFragment 读取文本而不是内容描述

android - 硬件加速支持的设备列表?

android - Android 模拟器加载缓慢的原因是什么?