2014-11-01 42 views
0

iam开发一个android应用程序,其中iam获取多个gcm通知当应用程序处于打开状态但所有应用程序关闭时,所有通知都以不同的数据打开但我只能获取多个通知一个打开,当我点击其他通知时,它不会重新启动具有不同数据的活动。只有一个gcm通知在Android应用程序关闭时打开

String title = intent.getExtras().getString("title"); 
    String message = intent.getExtras().getString("info"); 
    String lat = intent.getExtras().getString("lat"); 
    String lng = intent.getExtras().getString("lng"); 
    Intent notificationIntent = null; 
    if(title.equals("blockage")) 
    { 
     notificationIntent = new Intent(context, ViewBlockage.class); 

    } 
    else if(title.equals("icrequest")) 
    { 
     notificationIntent = new Intent(context, IntercarAlert.class); 
     message=intent.getExtras().getString("reqMessage"); // change the message here for request message 
     notificationIntent.putExtra("reqName", intent.getExtras().getString("userName")); 
    } 
    else if(title.equals("icresponse")) 
    { 
     notificationIntent = new Intent(context, InterCarResponseAlert.class); 
    } 
    notificationIntent.putExtra("title", title); 
    notificationIntent.putExtra("message", message); 
    notificationIntent.putExtra("lat", lat); 
    notificationIntent.putExtra("lng", lng); 
    int icon = R.drawable.ic_launcher; 
    long when = System.currentTimeMillis(); 
    NotificationManager notificationManager = (NotificationManager) 
    context.getSystemService(Context.NOTIFICATION_SERVICE); 
    Notification notification = new Notification(icon, message, when); 
    String appName = context.getString(R.string.app_name); 
    // set intent so it does not start a new activity 
    //notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent pIntent =PendingIntent.getActivity(context, gcmCounter, notificationIntent,PendingIntent.FLAG_UPDATE_CURRENT); 
    // update current must for every time get updated pending intent otherwise it will provide wrong intent values 
    notification.setLatestEventInfo(context, appName, message, pIntent); 
    notification.flags |= Notification.FLAG_AUTO_CANCEL; 
    // Play default notification sound 
    notification.defaults |= Notification.DEFAULT_SOUND; 
    // Vibrate if vibrate is enabled 
    notification.defaults |= Notification.DEFAULT_VIBRATE; 
    notificationManager.notify(gcmCounter, notification); 
    gcmCounter++; 
+0

你可以发布你的活动代码吗? – 2014-11-01 04:44:55

回答

0
notificationManager.notify(gcmCounter, notification); 

这里,每个时间变化gcmCounter的值。您可以一次在通知区域看到多个通知。

Documentation说:

如果具有相同ID的通知已经发布您的应用程序并没有被取消,它会被更新的信息所替代。

+0

我如何解决这个问题,因为当应用程序打开时,我可以看到所有通知与不同的数据集,但是当我收到所有通知,但只有打开一个。 – user1745334 2014-11-01 04:50:27

+0

好吧,现在我的所有通知打开,但首先我必须关闭已经打开的通知,然后打开其他如果我已经打开通知,我打开另一个什么都没有发生 – user1745334 2014-11-01 05:15:55

+0

随着身份证(gcmCounter在你的情况)取消你想要的通知,休息将仍然存在。 – 2014-11-01 05:21:47

0

intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);

FLAG_ACTIVITY_CLEAR_TASK清除以前的意图和当您单击通知时分配的新任务是否已经打开第一个通知。

相关问题