【问题标题】:Incoming call notification volume control stream来电通知音量控制流
【发布时间】:2017-11-10 03:59:57
【问题描述】:

我对来电使用全屏通知并通过以下方式播放铃声:

NotificationCompat.Builder mBuilder =
    new NotificationCompat.Builder(context)
        .setPriority(NotificationCompat.PRIORITY_HIGH)
        .setSmallIcon(smallIcon)
        .setContentIntent(contentIntent)
        .setContentTitle(title)
        .setContentText(text)
        .setVibrate(vibratePattern)
        .setSound(RingToneUtils.getDefaultRingtoneURI(), AudioManager.STREAM_RING)
        .setAutoCancel(false)
        .setLights(Color.argb(255, 0, 0, 255), 300, 300)
        .addAction(iconAction1, action1, answerActionPendingIntent)
        .addAction(iconAction2, action2, rejectActionPendingIntent)
        .setFullScreenIntent(contentIntent, true);

这可以正常工作,并在适当时显示为 HUD。问题是铃声音量是由通知音量流而不是铃声音量流控制的。

如何将这修正为铃声流?从技术上讲,这是一个通知,但对用户来说这似乎是错误的。

【问题讨论】:

  • 您是否正在寻找类似播放铃声的通知?
  • 不,它会播放铃声,正如您在 .setSound() 行中看到的那样。我想用铃声而不是通知音量来控制音量,因为它是铃声而不是通知音

标签: android notifications volume


【解决方案1】:

您可以像这样使用AudioManager 调整通知声音:

    AudioManager mgr=(AudioManager)getSystemService(Context.AUDIO_SERVICE);
    mgr.setStreamVolume(AudioManager.STREAM_RING, 0, AudioManager.FLAG_ALLOW_RINGER_MODES);

您可以将通知声音的音量设置为 0 到 10。希望这会有所帮助。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-31
    • 2012-01-01
    • 1970-01-01
    • 2014-10-23
    • 1970-01-01
    • 2023-01-24
    • 2022-11-01
    • 1970-01-01
    相关资源
    最近更新 更多