vibrate_when_ringing在Android棉花糖(6.0) [英] vibrate_when_ringing on Android Marshmallow (6.0)

查看:2366
本文介绍了vibrate_when_ringing在Android棉花糖(6.0)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code我有:

Settings.System.putInt(this.getContentResolver(), "vibrate_when_ringing", isVibrateWhenRinging ? 1 :0);

使用以下权限:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

从果冻豆(API 16),直到棒棒堂(API 22),这是工作的罚款

This was working fine from Jelly Bean (API 16) till Lollipop (API 22).

在Android的男,我知道,使用权限,我需要提示用户<一个href=\"http://developer.android.com/reference/android/provider/Settings.html#ACTION_MANAGE_WRITE_SETTINGS\"相对=nofollow> Settings.ACTION_MANAGE_WRITE_SETTINGS 。

In Android M, I know that for using that permission I need to prompt the user to Settings.ACTION_MANAGE_WRITE_SETTINGS.

然而,即使该权限打开,我看到了以下错误:

However, even with that permission turned on, I see the following error:

E/AndroidRuntime: java.lang.IllegalArgumentException: You cannot change private secure settings.
E/AndroidRuntime:     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:165)
E/AndroidRuntime:     at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
E/AndroidRuntime:     at android.content.ContentProviderProxy.call(ContentProviderNative.java:646)

呃......我缺少的东西?有了适当的权限,我们可以改变铃声,免打扰模式等,但它也像,随着版本的Andr​​oid M我们将不能够改变这样的正常设置,如震动响铃时。我希望我是错的。

Well... Am I missing something? With proper permissions we can change ringtones, do not disturb mode, etc. But it also looks like that with Android M we won't be able to change such a normal setting like "Vibrate when ringing". I hope I'm wrong.

推荐答案

您应该调用Settings.System.canWrite()看看,你可以写这个设置。

You should call Settings.System.canWrite() to see that you can to write this setting.

如果函数返回false,那么用户可以同意让您的应用程序写入设置:

If function returns false then the user can agree to allow your app to write to settings:

Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
intent.setData(Uri.parse("package:" + getApplicationContext().getPackageName()));
startActivity(intent);

这篇关于vibrate_when_ringing在Android棉花糖(6.0)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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