androidandroid-notificationsandroid-vibration

android: stop notification from vibrating


Hello i am building a notification with

NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(this, "default")
                .setShowWhen(false)
                .setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
                        .setMediaSession(mediaSession.getSessionToken())
                        .setShowActionsInCompactView(0, 1, 2))
                .setColor(getResources().getColor(R.color.colorPrimary))
                .setSmallIcon(android.R.drawable.stat_sys_headset)
                .setContentText(activeAudio.getArtist())
                .setContentTitle(activeAudio.getAlbum())
                .setContentInfo(activeAudio.getTitle())
                .addAction(android.R.drawable.ic_media_previous, "previous", playbackAction(3))
                .addAction(notificationAction, "pause", play_pauseAction)
                .addAction(android.R.drawable.ic_media_next, "next", playbackAction(2));

        ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE)).notify(NOTIFICATION_ID, notificationBuilder.build());

and i don't want the phone to vibrate whenever it's created. I've tried

.setVibrate(null)
.setVibrate(new Long[]{0l})
.setDefaults(Notification.DEFAULT_SOUND)

in all combinations, but with no effect. Any Ideas?


Solution

  • You must uninstall the application and reinstall Because it saves the settings from the first session

    As presented in this responsum

    For Android 8 or higher try it

    mNotificationChannel.setVibrationPattern(new long[]{ 0 }); 
    mNotificationChannel.enableVibration(true);