如果我使用firebase向我的应用程序发送3个推送数据通知,我首先点击的那个只打开,所有数据显示,当点击时休息2永远不会打开我的应用程序。下面是我给出的用于接收数据消息的代码,请看一下。
private void sendNotification(String message, Bitmap image, String objIdOS, String objIdVenInv, String typeVenInv, String cls, String checkTest, String colName, String title, String position) {
Intent intent = new Intent(this, UserLogin.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.putExtra("objIdOS",objIdOS);
intent.putExtra("objIdVenInv",objIdVenInv);
intent.putExtra("typeVenInv",typeVenInv);
intent.putExtra("cls",cls);
intent.putExtra("checkTest",checkTest);
intent.putExtra("colName",colName);
intent.putExtra("pos",position);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setAutoCancel(true)
.setSound( Uri.parse("android.resource://" + getPackageName() + "/" + R.raw.clean))
.setOnlyAlertOnce(true)
.setPriority(Notification.PRIORITY_MAX)
.setContentIntent(pendingIntent)
.setColor(Color.parseColor("#1ABC9C"))
.setSmallIcon(R.drawable.small_icon);
if (image!=null){
notificationBuilder.setStyle(new NotificationCompat.BigPictureStyle().bigPicture(image).setSummaryText(message)); /*Notification with Image*/
}
/*if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.splash_icon3));
} else {
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.splash_icon3));
}*/
NotificationManager notificationManager =
(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notificationBuilder.build());
}
答案 0 :(得分:1)
添加此
(int)SystemClock.currentThreadTimeMillis()
PendingIntent.getActivity(this, (int)SystemClock.currentThreadTimeMillis() /* Request code */, intent,
PendingIntent.FLAG_UPDATE_CURRENT);
notificationManager.notify((int)SystemClock.currentThreadTimeMillis(), notificationBuilder.build());
答案 1 :(得分:0)
更改这些 来自
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,PendingIntent.FLAG_ONE_SHOT);
收件人
int requestCode = new Random().nextInt();
PendingIntent contentIntent = PendingIntent.getActivity(this, requestCode,
notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
它将生成随机请求代码,以便在点击时可以打开多个通知。