如何在Android

时间:2019-09-20 13:02:25

标签: android firebase notifications firebase-cloud-messaging

实际上我是在android中实现聊天应用。我面临的问题是,当收到一个用户的多个通知时,当用户单击任何通知时,它将带用户到最后收到通知的用户的聊天中。然后我删除了待处理的意图标志,即PendingIntent.FLAG_UPDATE_CURRENT。删除后,始终将用户带到首先接收通知的用户聊天中。这就是我在做什么。我该如何解决这个问题?

private void showNotification(final Map<String, String> payload) {

    final RemoteViews normalLayout = new RemoteViews(getPackageName(), R.layout.custom_normal_notification);
    final RemoteViews expandedLayout = new RemoteViews(getPackageName(), R.layout.custom_expanded);
    initChannels(this);
    String imageUrl = payload.get("imageUrl");

    new NotificationsLoadImage(new NotificationsLoadImage.LoadImageCallback() {
        @Override
        public void Success(Bitmap bitmap) {
            value++;
            bitmap = getRoundedCroppedBitmap(bitmap, bitmap.getWidth());

            normalLayout.setImageViewBitmap(R.id.normal_notification_image, bitmap);
            normalLayout.setTextViewText(R.id.normal_notification_title, payload.get("username"));
            normalLayout.setTextViewText(R.id.normal_notification_description, payload.get("message"));
            expandedLayout.setImageViewBitmap(R.id.expanded_notification_image, bitmap);
            expandedLayout.setTextViewText(R.id.expanded_notification_title, payload.get("username"));
            expandedLayout.setTextViewText(R.id.expanded_notification_description, payload.get("message"));

            Intent intent = new Intent(MyFirebaseMessagingService.this, HomeScreen.class);
            //intent.setAction(Long.toString(System.currentTimeMillis()));
            PendingIntent _pendingIntent = PendingIntent.getActivity(MyFirebaseMessagingService.this, 0,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);
            expandedLayout.setOnClickPendingIntent(R.id.btn_reply, _pendingIntent);
            //  bitmap  = getCircleBitmap(bitmap);
            //Toast.makeText(MyFirebaseMessagingService.this, "Success", Toast.LENGTH_SHORT).show();

                builder = new NotificationCompat.Builder(MyFirebaseMessagingService.this, "default");
                builder.setSmallIcon(R.mipmap.ic_launcher);
                // builder.setLargeIcon(bitmap);
                // builder.setContentTitle(payload.get("username"));
                //builder.setContentText(payload.get("email"));
                builder.setDefaults(Notification.DEFAULT_SOUND);
                builder.setLights(Color.WHITE, 500, 500);
                builder.setStyle(new NotificationCompat.DecoratedCustomViewStyle());
                builder.setCustomContentView(normalLayout);
                builder.setCustomBigContentView(expandedLayout);
                builder.setAutoCancel(true);

                builder.setOngoing(false);
                builder.setWhen(Calendar.getInstance().getTimeInMillis());


                Intent _intent = new Intent(MyFirebaseMessagingService.this, MessageActivity.class);
                _intent.putExtra("Type","Notification");
                _intent.putExtra("userid", payload.get("senderID"));
                _intent.putExtra("token",payload.get("SenderToken"));
                _intent.putExtra("userCount", payload.get("userCount"));

                TaskStackBuilder stackBuilder = TaskStackBuilder.create(MyFirebaseMessagingService.this);
                stackBuilder.addNextIntent(_intent);
                PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
                builder.setContentIntent(pendingIntent);

                if (notificationManager != null) {
                    notificationManager.notify(Integer.parseInt(payload.get("userCount")), builder.build());
                    Toast.makeText(MyFirebaseMessagingService.this, "ID: " + payload.get("userCount"), Toast.LENGTH_SHORT).show();
                    id++;
                }





               // notificationManager.notify(Integer.parseInt(payload.get("userCount")), builder.build());

        }

        @Override
        public void Error(Exception e) {

        }
    }).execute(imageUrl);
}

0 个答案:

没有答案