【问题标题】:PendingIntent not working when adding extras in intent在意图中添加额外内容时,PendingIntent 不起作用
【发布时间】:2014-07-15 18:56:58
【问题描述】:

我已经实现了 GCMIntentService,每当我收到推送通知时,我都需要显示 通知菜单中的通知,并在 意图。 我可以在通知菜单中看到通知,但单击它什么也没做。以下是我正在使用的代码:-

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

我可以看到通知,但是当我单击它时,通知菜单会向上滑动并且没有 做任何事情都不会打开任何活动。 如果我没有在附加内容中发送任何捆绑包,那么我可以打开活动,但是当我发送时 捆绑值然后我无法打开活动。

提前致谢

【问题讨论】:

  • 你有日志吗?活动是否完全开放?在 Activity 中放置一些日志语句以确保它根本不会启动,并且不会在视图显示之前的某个其他点崩溃。也许还可以发布您的onReceive() 代码。
  • 没有,活动根本打不开
  • 嘿 abhishek 显示您的堆栈跟踪,因为当我尝试单击通知时它会打开活动..

标签: android android-intent notifications google-cloud-messaging


【解决方案1】:

我会尝试一次将附加内容添加到意图中:

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

【讨论】:

    【解决方案2】:

    嘿试试这个它对我有用

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

    如果它对你有用,请告诉我!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-04
      • 1970-01-01
      • 2012-05-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-01
      相关资源
      最近更新 更多