无法获得WRITE_SETTINGS权限 [英] Can't get WRITE_SETTINGS permission

查看:252
本文介绍了无法获得WRITE_SETTINGS权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Android M Preview 3上的目标API为23时,我似乎无法获得Manifest.permission.WRITE_SETTTINGS权限.

When I have a target API of 23 on Android M Preview 3, I cannot seem to acquire the Manifest.permission.WRITE_SETTTINGS permission.

 requestPermissions(new String[]{Manifest.permission.WRITE_SETTINGS},
              101);

请求权限不会打开我期望的对话框,但是如果我在没有此权限的情况下进行以下通话,

Request permission doesn't bring up the dialog I would expect, but if I make the following call without this permission,

 RingtoneManager.setActualDefaultRingtoneUri(activity, RingtoneManager.TYPE_RINGTONE, ringUri);

除了我没有许可之外,电话将不会显示.

The call will except because I don't have the permission.

我不确定从这里去哪里.是否有适用于23的新铃声API?还是此权限更改只是使任何非系统应用程序都无法更改铃声?

I'm not sure where to go from here. Is there a new ringtone API for 23? Or did this permission change just make it impossible for any non-system apps to change the ringtone?

推荐答案

根据文档使用WRITE_SETTINGS:

  1. 清单中的<uses-permission>元素与往常一样.

致电Settings.System.canWrite() 查看您是否有资格写出设置.

Call Settings.System.canWrite() to see if you are eligible to write out settings.

如果canWrite()返回false,请启动 ACTION_MANAGE_WRITE_SETTINGS活动,以便用户可以在那里同意允许您的应用实际写入设置.

If canWrite() returns false, start up the ACTION_MANAGE_WRITE_SETTINGS activity so the user can agree there to allow your app to actually write to settings.

换句话说,现在写入设置是一种双重选择(同意安装,可以在设置"中单独同意以允许),类似于设备管理API,可访问性服务等.

In other words, writing to settings is now a double-opt-in (agree to install, agree separately in Settings to allow), akin to device admin APIs, accessibility services, etc.

还请注意,我尚未尝试使用这些—这基于我昨天在Android上进行的研究6.0更改.

Also note that I have not tried using these yet — this is based on research that I did yesterday on Android 6.0 changes.

这篇关于无法获得WRITE_SETTINGS权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆