Android - notificationManager.notify不显示通知

时间:2016-05-15 18:45:31

标签: android

我试图在Android上显示简单的本地通知消息。这是我的代码,但我无法使其正常工作。

没有采取行动:

final Context context = this;
Intent intent = new Intent(this, MainActivity.class);
final PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

    Notification n=new Notification.Builder(context)
                                    .setContentTitle("Nabeeer?")
                                    .setContentText("Iceriiik")
                                    .setContentIntent(null)
                                    .setContentIntent(pIntent)
                                    .setAutoCancel(true)
                                    .build();

                            NotificationManager notificationManager =
                                    (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

                            notificationManager.notify(0, n);

1 个答案:

答案 0 :(得分:2)

您需要在通知中添加一个图标:

.setSmallIcon(R.drawable.youricon)

官方文档中没有记录:您需要添加一个小图标,否则为the notification won't show