无法获得 WRITE_SETTINGS 权限 [英] Can't get WRITE_SETTINGS permission
问题描述
当我在 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
,基于文档:
在清单中正常使用
元素.
调用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屋!