Android 即使在后台,如何以最大音量播放通知声音?

Android 即使在后台,如何以最大音量播放通知声音?,android,android-studio,android-notifications,Android,Android Studio,Android Notifications,当收到通知时,我需要在Android中播放声音,即使是在后台。这就像Uber Driver或其他应用程序一样:即使手机处于静音状态且应用程序处于后台,它们也会以最大音量播放声音 我试过了,但运气不好: AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0); au

当收到通知时,我需要在Android中播放声音,即使是在后台。这就像Uber Driver或其他应用程序一样:即使手机处于静音状态且应用程序处于后台,它们也会以最大音量播放声音

我试过了,但运气不好:

AudioManager audioManager = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, 20, 0);
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_RAISE, AudioManager.FLAG_SHOW_UI);
有什么建议吗?

检查代码

notificationBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_通知))