Vibrate and Sound defaults on notification

后端 未结 9 1157
天涯浪人
天涯浪人 2020-12-04 07:37

I\'m trying to get a default vibrate and sound alert when my notification comes in, but so far no luck. I imagine it\'s something to do with the way I set the defaults, but

9条回答
  •  长情又很酷
    2020-12-04 08:34

    An extension to TeeTracker's answer,

    to get the default notification sound you can do as follows

    NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_notify)
                .setContentTitle("Device Connected")
                .setContentText("Click to monitor");
    
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    builder.setSound(alarmSound);
    

    This will give you the default notification sound.

提交回复
热议问题