Android姜饼中的NotificationCompat不起作用

时间:2014-07-07 08:40:44

标签: android

我曾经阅读过this topic about NotificationCompat,我知道在Gingerbread及其下方需要contentIntent。但是,我在android Gingerbread工作,我不想添加PendingIntent。如何获得正确的通知我该怎么做? 谢谢你的帮助

NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setAutoCancel(true);
    builder.setContentTitle("Basic notification");
    builder.setContentText(content);
    builder.setSmallIcon(R.drawable.ic_launcher);

    Notification notification = builder.build();
    try {
        NotificationManager manager = (NotificationManager) this
                .getSystemService(NOTIFICATION_SERVICE);

        manager.notify(8, notification);
    } catch (Exception e) {
        Log.i("Exception", e.getMessage()); 
    }

异常:需要contentIntent:pkg = com.example.notificationtutorial id = 8 notification =通知(vibrate = null,sound = null,defaults = 0x0,flags = 0x10)

1 个答案:

答案 0 :(得分:0)

您需要为通知设置contentIntent。

在您的情况下,您必须在通知中创建PendingIntent和setter PendingIntent。

notification.contentIntent = notificationIntent;

否则你会收到消息,通知的contentIntent为null,因为它没有设置。

文档在这里:Notification.html#contentIntent

示例:NotificationCompat Example