Android如何以编程方式打开请勿打扰(DND) [英] Android how to turn on do not disturb (dnd) programmatically

查看:59
本文介绍了Android如何以编程方式打开请勿打扰(DND)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Android中以编程方式打开/关闭请勿打扰"(dnd)?希望这能给我带来一些好处,但事实并非如此:

How do I turn on/off 'do not disturb' (dnd) programmatically in Android? Is was hoping this would give me something but it doesn't:

Settings.System.putInt(getContentResolver(), Settings.System.DO_NOT_DISTURB, 1);

推荐答案

我找到了这个解决方案:

I found this solution:

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.setInterruptionFilter(NotificationManager.INTERRUPTION_FILTER_NONE);

它要求:

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

据我所知,执行requestPermissions()时不会弹出请求对话框.必须通过设置菜单设置"->声音和声音"来授予它.通知->请勿打扰访问.

Which as far as I can tell does not pop up a request dialog when doing requestPermissions(). It has to be granted through the settings menu Settings -> Sound & Notifcation -> Do Not Disturb Access.

这是在SDK 23棉花糖上.

This is on SDK 23 Marshmallow.

这篇关于Android如何以编程方式打开请勿打扰(DND)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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