时间:2011-04-18 12:44:55

标签: android android-pendingintent notification-bar

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

请帮忙......

1 个答案:

答案 0 :(得分:2)

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

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