How to set the Permission WRITE_SECURE_SETTINGS in android? [duplicate]

こ雲淡風輕ζ 提交于 2019-12-10 01:36:32

问题


I am trying to enable the Accessibility Service Settings above 4.0 but It is showing an Exception i.e.,

Caused by: java.lang.SecurityException: Permission denial: writing to secure settings requires android.permission.WRITE_SECURE_SETTINGS

In Manifest I have Declared This permission like this.

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

But in manifest giving compilation Error i.e., Permission is only System Apps. So i am not Understanding how to resolve this issue.

Thanks in advance

Here is my sample code

if (Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ACCESSIBILITY_ENABLED).contains("1")) {
            if (Settings.Secure.getString(getContentResolver(),
                    Settings.Secure.ACCESSIBILITY_ENABLED).contains("1")) {
                System.out.println("Putting the Value to Enable..");
                Settings.Secure.putInt(getContentResolver(),
                        Settings.Secure.ACCESSIBILITY_ENABLED, 0);
            } else {
                Settings.Secure.putInt(getContentResolver(),
                        Settings.Secure.TOUCH_EXPLORATION_ENABLED, 1);
            }
        }

回答1:


WRITE_SECURE_SETTINGS is not available to applications. No app outside of the system/firmware can get that permisssion.

Please check this answer



来源:https://stackoverflow.com/questions/19538809/how-to-set-the-permission-write-secure-settings-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!