Vibrate Not working with Notification

Achayan picture Achayan · Dec 28, 2014 · Viewed 7.9k times · Source

I am trying to set vibrate and sound for notification. For some reason its not working for me :( Here is the code what I am trying

NotificationManager notificationManager = getNotificationManager();
        NotificationCompat.Builder builder = new NotificationCompat.Builder(
                context);
        builder.setSound(alarmSound);
        builder.setVibrate(new long[] { 1000, 1000, 1000 });
        Notification notification = builder.setContentIntent(contentIntent)
                .setSmallIcon(icon).setTicker(title).setWhen(0)
                .setAutoCancel(true).setContentTitle(title).setPriority(Notification.PRIORITY_HIGH)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(msgToDisply))
                .setContentText(msgToDisply).build();
        notificationManager.notify(NOTIFICATION, notification);
        stopSelf();

And

public NotificationManager getNotificationManager() {
        return (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    }

And I have permission in my manifest

<uses-permission android:name="android.permission.VIBRATE" />

Any clue what's going on ?

Answer

Panayiotis Irakleous picture Panayiotis Irakleous · Dec 29, 2014

add this

notification.defaults|= Notification.DEFAULT_SOUND;
notification.defaults|= Notification.DEFAULT_LIGHTS;
notification.defaults|= Notification.DEFAULT_VIBRATE;