不能使用RingtoneManager.setActualDefaultRingtoneUri由于缺少权限,甚至当我要求他们当我、权限、RingtoneManager、setActualDefault

2023-09-12 23:39:56 作者:暮雨而桐

当我有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 ,根据文档:

<使用-许可> 中的表现为正常的元素

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

Call Settings.System.canWrite() ,看看您是否有资格写出来的设置。

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

如果 canWrite()返回,启动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.

 
精彩推荐