0

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});


    }
Nawaz
  • 63
  • 1
  • 2
  • 9
  • i think you need to enable vibration in firebase console. check [this](http://stackoverflow.com/questions/38446300/firebase-cloud-messaging-notification-vibration) – Mehran Zamani Feb 12 '17 at 15:36

1 Answers1

1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Ok.. let me chack – Nawaz Feb 12 '17 at 15:27
  • No Change `notification.setVibrate(new long[] { 1000, 1000}); NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(0, notification.build());` – Nawaz Feb 12 '17 at 15:47