1

我已经实现了GCMIntentService,并且每当我得到推送通知时,我都需要在通知菜单中显示 通知,并使用 意图中的某些包值打开活动。 我可以在通知菜单中看到通知,但点击它只是不会做任何事情。以下是我使用的代码: -PendingIntent在意图添加附加内容时不起作用

mNotificationManager = (NotificationManager) 
      this.getSystemService(Context.NOTIFICATION_SERVICE); 

    Intent i = new Intent(this, ChatDetail.class); 
    Bundle b = new Bundle(); 
    b.putString("my_id", "5356b178b130a74a57019fe9"); 
    b.putString("you_id", youId); 
    i.putExtras(b); 
    //  PendingIntent contentIntent = PendingIntent.getActivity(this, 0, 
    //    new Intent(this, MainActivity.class), 0); 
      PendingIntent contentIntent = PendingIntent.getActivity(this, 0,  
        i,PendingIntent.FLAG_CANCEL_CURRENT); 

    NotificationCompat.Builder mBuilder = 
      new NotificationCompat.Builder(this) 
    .setSmallIcon(R.drawable.pool_my_ride_icon) 
    .setContentTitle("GCM Notification") 
    .setStyle(new NotificationCompat.BigTextStyle() 
    .bigText(text)) 
    .setContentText(text); 

    mBuilder.setContentIntent(contentIntent); 
    mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build()); 

我可以看到该通知,但是当我点击它通知菜单向上滑动,不 做任何事情,不打开任何活动。 如果我不发送任何捆绑的额外产品,那么我可以打开该活动,但是当我发送 捆绑包价值时,我无法打开该活动。

在此先感谢

+0

你有没有记录?活动是否开放?在活动中放入一些日志语句,以确保它根本不会启动,并且在可以显示视图之前不会在其他某个点崩溃。也许还会发布你的'onReceive()'代码。 –

+0

没有活动根本没有打开 – abhishek

+0

嘿abhishek显示你的stacktrace,因为当我试图打开活动时点击通知.. – goonerDroid

回答

0

我会想办法的额外一次添加到一个意向:

i.putExtra("my_id", "5356b178b130a74a57019fe9"); 
i.putExtra("you_id", youId); 
+0

试过它,不起作用 – abhishek

0

哎试试这个它为我工作

Intent i = new Intent(this, ChatDetail.class); 
Bundle b = new Bundle(); 
b.putString("my_id", "5356b178b130a74a57019fe9"); 
b.putString("you_id", youId); 
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
      Intent.FLAG_ACTIVITY_SINGLE_TOP); 
i.putExtras(b); 

重要这里指的是发送额外的标志,实际上希望您的交付意图

i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 
      Intent.FLAG_ACTIVITY_SINGLE_TOP); 

只要让我知道它是否适合你!

相关问题