0

I need to show a notification without playing a notification sound using notification builder.

I tried using

set sound(null);

And I have also tried using the custom sound

Here is my code:

public NotificationCompat.Builder getChannelNotification() {
   getData();
    return new NotificationCompat.Builder(getApplicationContext(), channelID)
            .setContentTitle(time)
            .setContentText(text)
            .setSmallIcon(R.drawable.ic_android)
            .setDefaults(0)
            .setPriority(NotificationCompat.PRIORITY_LOW)
            .setAutoCancel(true)
            .setOnlyAlertOnce(true)
            .setSound(null);

}
Taslim Oseni
  • 6,086
  • 10
  • 44
  • 69
gaspar
  • 9
  • 3

1 Answers1

0

Remove the line to builder.setDefaults(0); . It will not play the sound, but you may need to enable all other notification defaults if preferred

Cyrille Con Morales
  • 918
  • 1
  • 6
  • 21