第一次通知活动显示时,第二次通知中未显示GCM通知活动

问题描述 投票:0回答:1

我在Android设备中实现了Android应用程序,我也收到了来自服务器的通知。但是我面临的问题是,当第一个通知数据的接收活动打开时,当我收到第二个通知时,点击第2个通知,它没有用更新的通知数据替换Receive活动。请帮帮我

正在使用以下代码: -

private void sendNotification(String msg) {
    Log.d(TAG, "Preparing to send notification...: " + msg);
    mNotificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    Context context = getApplicationContext();

    //Notification notification = new Notification(icon, message, when); //UM
    Log.e(TAG, "Input Extra is...: " + msg);
    Intent notificationIntent = new Intent(context, ResultShowActivity.class);
    notificationIntent.putExtra("Message",msg);
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP );

    int iUniqueId = (int) (System.currentTimeMillis() & 0xfffffff);
    int when= (int) System.currentTimeMillis() ;
    //PendingIntent contentIntent = PendingIntent.getActivity(this, iUniqueId,notificationIntent, 0);
    PendingIntent contentIntent = PendingIntent.getActivity(this, iUniqueId,notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT );
    Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this).setSmallIcon(R.drawable.gcm_cloud)
            .setContentTitle("GCM Notification")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
            .setAutoCancel(true)
            .setSound(alarmSound)
            .setContentText(msg);

    mBuilder.setContentIntent(contentIntent);
    //mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    mNotificationManager.notify(when, mBuilder.build());
    Log.d(TAG, "Notification sent successfully.");
}
android google-cloud-messaging
1个回答
0
投票

欢迎来到Stack Overflow!为了充分利用本网站,您可能希望更加具体地了解您的问题。也许添加受影响的代码。

在你的情况下,看起来问题是围绕你的PendingIntent标志。添加FLAG UPDATE CURRENT以更新extras包,如果这是你想要做的。

© www.soinside.com 2019 - 2024. All rights reserved.