繁体   English   中英

Firebase 多个推送通知不起作用

[英]Firebase multiple push notification not working

如果我使用 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());
}

添加这个

    (int)SystemClock.currentThreadTimeMillis()

    PendingIntent.getActivity(this, (int)SystemClock.currentThreadTimeMillis() /* Request code */, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);


notificationManager.notify((int)SystemClock.currentThreadTimeMillis(), notificationBuilder.build());

将这些从

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

它将生成随机请求代码,以便点击时可以打开多个通知..

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM