Android 通知栏点击不起作用

发布于 2024-11-01 21:39:05 字数 903 浏览 4 评论 0原文

我有以下代码在 C2DMReceiver.java 的通知栏中发出通知。这个类本身扩展了BroadcastReceiver。以下代码位于 onReceive 方法中。

    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.ic_call;
    CharSequence text = "Match Found";
    CharSequence contentTitle = "Match";
    CharSequence contentText = received.getExtras().getString("matches");
    long when = System.currentTimeMillis();

    Intent intent = new Intent(context, C2DMReceiver.class);


    PendingIntent contentIntent =  PendingIntent.getBroadcast(context, 0, intent, 0);

    Notification notification = new Notification(icon,text,when);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    notificationManager.notify(34, notification);

现在,当我单击通知栏中的通知时。 c2DmReceiver 类的 onReceive 方法未调用。

请帮忙...

I have following code to make notification in notification bar in C2DMReceiver.java. This class itself extends BroadcastReceiver. and following code is in onReceive method.

    NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);

    int icon = R.drawable.ic_call;
    CharSequence text = "Match Found";
    CharSequence contentTitle = "Match";
    CharSequence contentText = received.getExtras().getString("matches");
    long when = System.currentTimeMillis();

    Intent intent = new Intent(context, C2DMReceiver.class);


    PendingIntent contentIntent =  PendingIntent.getBroadcast(context, 0, intent, 0);

    Notification notification = new Notification(icon,text,when);

    notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

    notificationManager.notify(34, notification);

Now when I am clicking on notification in notification bar. onReceive method of c2DmReceiver class is not invoking.

Please help...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋情葬爱 2024-11-08 21:39:05

您是否在 Manifest 文件中注册了 C2DMReceiver?如果您已经注册,请尝试将以下行更改为Manifest文件中相应的IntentFilter并检查。

Intent intent = new Intent(context, C2DMReceiver.class);

Did you registered C2DMReceiver in your Manifest file? If you have registered, try changing the below line to the corresponding IntentFilter in Manifest file and check.

Intent intent = new Intent(context, C2DMReceiver.class);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文