How to stop android notification ringtone after 30 seconds?

前端 未结 3 1917
难免孤独
难免孤独 2021-02-04 12:26

I\'m writing an app that notifies a user of very time sensitive information, and I think a lot of them would want to use a phone ringtone instead of just the short notification

3条回答
  •  南笙
    南笙 (楼主)
    2021-02-04 13:10

    This should do it.

    ....
    mediaPlayer.start();
    ....
    final Handler handler = new Handler();
        handler.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (mediaPlayer.isPlaying())
                    mediaPlayer.stop();
            }
        }, timeout);
    

提交回复
热议问题