通知振动不起作用

时间:2017-02-12 15:11:31

标签: android notifications

我正在尝试为firebase通知设置振动 但我认为我做得不对

这是一个代码,

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 个答案:

答案 0 :(得分:1)

您需要在调用Notification之前配置notify() 调用setVibrate()后,您正在呼叫notify() 。将setVibrate()来电移至notify()来电之前。

另请注意,您需要在清单中为<uses-permission>权限设置VIBRATE元素。