手机静音时有声音通知 [英] Notification with sound although phone is muted
本文介绍了手机静音时有声音通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用Android的NotificationManager创建通知.
I am creating a notification with Android's NotificationManager.
是否可以以始终播放通知的声音的方式覆盖"电话的音量(静音)设置?
Is it possible to 'override' the phone's volume (mute) settings in such a way, that the notification's sound is ALWAYS played?
我需要这个的原因如下: 该通知非常重要,以至于仅靠振动可能还不够.必须提醒用户.因此,即使手机已静音或音量很低,也应播放声音.
The reason I need this is the following: The notification is so important, that vibration alone may not be enough. The user MUST be alerted. So a sound shall be played, even if the phone is muted or the volume is very low.
推荐答案
是的,
MediaPlayer mMediaPlayer;
Uri notification = null;
notification = RingtoneManager
.getDefaultUri(RingtoneManager.TYPE_ALARM);
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDataSource(ctx, notification);
// mMediaPlayer = MediaPlayer.create(ctx, notification);
final AudioManager audioManager = (AudioManager) ctx
.getSystemService(Context.AUDIO_SERVICE);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
mMediaPlayer.prepare();
// mMediaPlayer.start();
mMediaPlayer.setLooping(true);
mMediaPlayer.setOnPreparedListener(new OnPreparedListener() {
public void onPrepared(MediaPlayer arg0) {
mMediaPlayer.seekTo(0);
mMediaPlayer.start();
}
});
这篇关于手机静音时有声音通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文