2

我有以下代码在 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 方法未调用。

请帮忙...

4

1 回答 1

2

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

Intent intent = new Intent(context, C2DMReceiver.class);
于 2011-04-18T13:29:07.230 回答