不能使用RingtoneManager.setActualDefaultRingtoneUri由于缺少权限,甚至当我要求他们 [英] Can't use RingtoneManager.setActualDefaultRingtoneUri due lack of permissions, even when I'm requesting them

查看:499
本文介绍了不能使用RingtoneManager.setActualDefaultRingtoneUri由于缺少权限,甚至当我要求他们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我有23对Android的M preVIEW 3目标API,我似乎无法获得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. <使用-许可> 中的表现为正常的元素

  1. Have the <uses-permission> element in the manifest as normal.

<一个href="http://developer.android.com/reference/android/provider/Settings.System.html#canWrite%28android.content.Context%29">Call Settings.System.canWrite() ,看看您是否有资格写出来的设置。

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

如果 canWrite()返回,启动<一个href="http://developer.android.com/reference/android/provider/Settings.html#ACTION_MANAGE_WRITE_SETTINGS">the 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.

IOW,写入设置现在是一个双选入(同意安装,另外同意在设置中允许),类似于设备管理的API,可访问性服务等。

IOW, 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.

另外请注意,我还没有使用这些尚未&mdash尝试;这是基于我昨天在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.

这篇关于不能使用RingtoneManager.setActualDefaultRingtoneUri由于缺少权限,甚至当我要求他们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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