【问题标题】:NotificationCompat in Android gingerbread doesn't workAndroid 姜饼中的 NotificationCompat 不起作用
【发布时间】:2014-07-07 16:46:16
【问题描述】:

我曾经阅读过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=Notification(vibrate=null,sound=null,defaults=0x0,flags=0x10)

【问题讨论】:

    标签: android


    【解决方案1】:

    您需要为通知设置 contentIntent。

    在您的情况下,您必须在通知中创建 PendingIntent 并设置 PendingIntent。

    notification.contentIntent = notificationIntent;
    

    否则您将收到消息,通知的 contentIntent 为空,因为它没有设置。

    文档在这里:Notification.html#contentIntent

    例如:NotificationCompat Example

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多