BroadwayMayField
BroadwayMayField

Reputation: 57

Android Notification Sound to Silent

I have a custom notification that I built, every time it pops up it sends a notification sound. I want this to be silent and not make any sound. I have trying using everything below but nothing seems to work. Everything seems to be deprecated and setPriority() is not an option. Looking for solution on how to get the notification sound to be silent, any help? My code is below.

Tried using a combination of all below:

    status.sound = null;
    status.vibrate = null;
    status.defaults &= ~DEFAULT_SOUND;
    status.defaults &= ~DEFAULT_VIBRATE;
    status.vibrate = new long[] { -1 };
    status.priority = -2

My Code

    Notification status = new NotificationCompat.Builder(this, CHANNEL_1_ID).build();
    status.contentView = views;
    status.bigContentView = bigViews;
    status.flags = Notification.FLAG_ONGOING_EVENT;
    status.icon = R.drawable.ic_music_note;
    status.contentIntent = pendingIntent;
    status.priority = -2;
    startForeground(Constants.NOTIFICATION_ID.FOREGROUND_SERVICE, status);

Upvotes: 2

Views: 4723

Answers (1)

Abhi
Abhi

Reputation: 3511

To mute notification sounds in API 26, use the IMPORTANCE_LOW channel, which doesn't contain any sound. Example:

 int importance = NotificationManager.IMPORTANCE_LOW;

Also, make sure to clear app data or reinstall the app in order to have this change take effect in notification channel after changing the importance.

Reference Documentation: Migrating MediaStyle Notifications to Support Android O

Upvotes: 3

Related Questions