How to give permission for changing screen brightness in Marshmallow

家住魔仙堡 提交于 2019-12-04 09:02:01

From API 23 you should ask dynamically from the user if they have the WRITE_SETTINGS permission by using Settings.System.canWrite(context). If you want the user approve the setting, you should start an intent with action ACTION_MANAGE_WRITE_SETTINGS. The code you probably need is something like follows:

if (Settings.System.canWrite(context))
{
    // perform your actions
}
else
{
    Intent intent = new Intent(android.provider.Settings.ACTION_MANAGE_WRITE_SETTINGS)
    .setData(Uri.parse("package:" + getActivity().getPackageName()))
    .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!