Nawaz
Nawaz

Reputation: 63

Notification Vibration Not Working

I am trying to set vibration for firebase notification but I think I am not doing it right

here is a code,

public void onMessageReceived(RemoteMessage remoteMessage) {
        Intent intent = new Intent(this, MainActivity.class);
        intent.setFlags(intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
        NotificationCompat.Builder notification = new NotificationCompat.Builder(this);
        notification.setContentTitle("NEW NOTIFICATION");
        notification.setContentText(remoteMessage.getNotification().getBody());
        notification.setAutoCancel(true);
        Bitmap icon = BitmapFactory.decodeResource(getApplicationContext().getResources(),R.drawable.icon);
        notification.setSmallIcon(R.mipmap.ic_launcher);
        notification.setLargeIcon(icon);
        notification.setContentIntent(pendingIntent);
        NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(0, notification.build());
        notification.setVibrate(new long[] { 1000, 1000});


    }

Upvotes: 0

Views: 761

Answers (1)

CommonsWare
CommonsWare

Reputation: 1006869

You need to configure the Notification before calling notify(). You are calling setVibrate() after calling notify(). Move your setVibrate() call to be before the notify() call.

Also note that you need to have a <uses-permission> element for the VIBRATE permission in your manifest.

Upvotes: 1

Related Questions