gpt4 book ai didi

android - 如何在Android 7.1上设置最大声音

转载 作者:行者123 更新时间:2023-12-02 23:34:29 25 4
gpt4 key购买 nike

打开设置为最大的应用程序声音。

NotificationManager n = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if(n.isNotificationPolicyAccessGranted()) {
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
int maxVolume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_ALARM);
mAudioManager.setStreamVolume(AudioManager.STREAM_ALARM, maxVolume, 15);

}else{
// Ask the user to grant access
Intent intent = new Intent(android.provider.Settings.ACTION_NOTIFICATION_POLICY_ACCESS_SETTINGS);
startActivityForResult(intent,99);
}

我使用了这段代码android 7.1.1,没有运气。
请你帮助我好吗。

最佳答案

I've used this code android 7.1.1 and no luck.


因为从N开始,否则不允许切换“请勿打扰”的音量调整,除非已授予该应用“请勿打扰”访问权限。参见 isNotificationPolicyAccessGranted(). boolean isNotificationPolicyAccessGranted ()

added in API level 23

Checks the ability to read/modify notification do not disturb policy for the calling package.

Returns true if the calling package can read/modify notification policy.


阅读有关 setStreamVolume() AudioManager 的更多信息

关于android - 如何在Android 7.1上设置最大声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47884153/

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