Вибрация уведомлений не работает

Я пытаюсь настроить вибрацию для оповещения о пожаре, но думаю, что я делаю это неправильно

вот код,

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


    }

1 ответ

Вам необходимо настроить Notification перед звонком notify(), Ты звонишь setVibrate() после звонка notify(), Переместить ваш setVibrate() призывать быть до notify() вызов.

Также обратите внимание, что вам нужно иметь <uses-permission> элемент для VIBRATE разрешение в вашем манифесте.

Другие вопросы по тегам