Android - 将通知发布到状态栏?

标签 android notifications notificationmanager

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

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还必须提供。

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

关于Android - 将通知发布到状态栏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19871905/

相关文章:

Android:通知中的新信息替换旧信息

android - 如何在我的应用程序关闭之前一直显示我的 Android 通知?

android - Android 中的谷歌地图缩放错误

javascript - Chrome 桌面通知示例

android - SwipeRefreshLayout 在 onRefresh() 开始之前检测向下滑动事件

android - 使用用户的 UID 发送 Firebase 云消息

android - 是否可以在 android 通知文本中显示笑脸/表情/图像跨度?

android - 如何更改声音的输出音量?

android - 从 ArrayList 中获取字符串并保存在共享首选项中

java - Kotlin 类作为 junit 测试运行,即使它在 androidTest 包中 - 对于 Java 类它正常运行