【问题标题】:Android - Post a notification to status bar?Android - 向状态栏发布通知?
【发布时间】:2013-11-09 03:03:44
【问题描述】:

我试图在没有任何意图的情况下向状态栏发布通知,但没有任何反应? 我错过了什么吗?此代码在我的推送通知接收器服务中。

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

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
    builder.setContentTitle("Hello");
    builder.setContentTitle("This is my message");
    builder.setSmallIcon(R.drawable.ic_launcher);

    PendingIntent intent = PendingIntent.getActivity(this, 0, new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setFullScreenIntent(intent, true);

    notificationManager.notify(555, builder.build());

【问题讨论】:

  • 您还需要small icon。此外,如果您希望此代码在 2.2 和 2.3 上运行,则需要一个 Intent
  • 太棒了,请将其发布为答案,以便我接受
  • 完成。很高兴看到您的问题已解决!
  • 顺便提一下,您调用了两次 setContentTitle。

标签: android notifications notificationmanager


【解决方案1】:

正如我在评论中提到的,要为通知管理器创建通知,还必须提供small icon

此外,对于同时面向 Android 2.2 和 2.3 的开发人员,请确保包含内容 Intent,否则应用程序将崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-15
    • 2016-02-22
    • 1970-01-01
    相关资源
    最近更新 更多