Notification with sound although phone is muted

前端 未结 2 880
轻奢々
轻奢々 2021-01-12 19:03

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 notifica

2条回答
  •  天涯浪人
    2021-01-12 19:46

    yes it is possible,

    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();
    
                }
    
            });
    

提交回复
热议问题