Bor*_*ris 4 notifications android android-notifications
我正在使用Android的NotificationManager创建通知.
是否有可能以这种方式"覆盖"手机的音量(静音)设置,通知的声音始终播放?
我需要这个的原因如下:通知非常重要,单靠振动可能还不够.必须提醒用户.因此,即使手机静音或音量很低,也应播放声音.
小智 7
对的,这是可能的,
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();
}
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2197 次 |
| 最近记录: |