我试图在没有任何 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/