gpt4 book ai didi

android - 没有 "don' t 打扰的静音电话"

转载 作者:行者123 更新时间:2023-12-01 23:36:29 31 4
gpt4 key购买 nike

至少在 Pixel 手机上,可以将手机从设置中静音。但是,从屏幕截图中可以看出,我没有找到任何将手机设置为这种模式的 Android API。 enter image description here如果我使用 AudioManager使用 setRingerMode手机设置为振动模式和/或显示“请勿打扰”图标。有谁知道如何使用这个功能?

最佳答案

确保您已在 AndroidManifest.xml 中声明以下权限文件。

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

编辑 2

我还在 上进行了测试谷歌像素 2 API 28 它按预期工作。

enter image description here

如您所见,通知栏中没有“请勿打扰(DND)”按钮。

编辑
audioManager.setStreamVolume(AudioManager.STREAM_RING, 0, 0)无需“请勿打扰”图标即可让您实现所需的功能。

输出

enter image description here

原创

AudioManger's方法名称 setRingerMode(int ringerMode)允许您设置所需的模式。

文档:

Silent mode will mute the volume and will not vibrate. Vibrate mode will mute the volume and vibrate. Normal mode will be audible and may vibrate according to user settings.

This method has no effect if the device implements a fixed volume policy as indicated by isVolumeFixed().

From N onward, ringer mode adjustments that would toggle Do Not Disturb are not allowed unless the app has been granted Do Not Disturb Access. See NotificationManager#isNotificationPolicyAccessGranted().


/**
* Changes mobile profile to "Silent" or "Vibrate" or "Normal" mode
*
* @param context
* @param mode - "0 - Silent"
* - "1 - Vibrate"
* - "2 - Normal"
*/
public static void chooseProfile(Context context, int ringerMode) {
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
if (ringerMode == 0)
audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT);
else if (ringerMode == 1)
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
else if (ringerMode == 2)
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
}

另见:

getRingerMode()

isVolumeFixed()

关于android - 没有 "don' t 打扰的静音电话",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57832788/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com