我正在尝试为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});
}
答案 0 :(得分:1)
您需要在调用Notification
之前配置notify()
。 调用setVibrate()
后,您正在呼叫notify()
。将setVibrate()
来电移至notify()
来电之前。
另请注意,您需要在清单中为<uses-permission>
权限设置VIBRATE
元素。