How to show a notification without a sound java

后端 未结 11 1705
鱼传尺愫
鱼传尺愫 2020-12-11 15:09

How can I make a notification that doesn\'t make a sound when I build it? I am building a notification, and my users don\'t like the fact that it makes a sound.

11条回答
  •  隐瞒了意图╮
    2020-12-11 15:33

    Easy way to go to be able to show notification with any kind of priority is to set some sound that is silence actually. Just generate some silence.mp3 put it in "raw" folder and set notification sounds using Uri:

    Uri.parse("android.resource://"+YOUR_APP_PACKAGE_NAME+"/"+R.raw.silence) 
    

    You can generate this .mp3 with app like Audacity. It has option generate silence, just set how many seconds and you are good to go.

    If you set defaults to 0 and set sound to null, notification will be shown without you hearing it but you wont be able to show notifications with some higher priority.

提交回复
热议问题