在意图添加额外时的PendingIntent不工作 [英] PendingIntent not working when adding extras in intent

查看:127
本文介绍了在意图添加额外时的PendingIntent不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有GCMIntentService实施每当我得到的推送通知我需要显示
在通知菜单中的通知和开放的活动与在某些束值
意图。
我可以看到在通知菜单中的通知,但点击它只是没有做任何事情。以下是code,我现在用的: -

I have GCMIntentService implemented and whenever i get the push notification i need to show the notification in notification menu and open an activity with some bundle values in the intent. I can see the notification in the notification menu but clicking on it just doesn't do anything. Following is the code which i am using :-

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

我可以看到通知,但是当我点击它的通知菜单向上滑动,并且不
做任何事情,不打开任何活动。
如果我没有在演员发送任何包,然后我可以打开相应的活动,但是当我送
束值,然后我无法打开活动。

I can see the notification but when i click on it the notification menu slides up and doesn't do anything doesn't opens any activity. If i don't send any bundle in the extras then i can open the activity but when i send bundle values then i can't open the activity.

在此先感谢

推荐答案

哎试试这个它为我工作

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

在这里很重要的一点是要发送额外的标志其实是想你的意图传递

the important point here is to send the additional flags to actually want your intent to be delivered

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

只是让我知道,如果它为你工作!

Just let me know if it worked for you!

这篇关于在意图添加额外时的PendingIntent不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆