在 Android 5.0.1 中显示通知

Show notification in Android 5.0.1

我想在我的 Android 应用程序中创建通知,但我的代码不起作用!

NotificationManager nManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

Notification.Builder nBuilder = new Notification.Builder(this);
nBuilder.setContentTitle("Title...");
nBuilder.setContentText("Text...");
nBuilder.setContentInfo("Info?");
nBuilder.setWhen(System.currentTimeMillis());

//Intent notificationIntent = new Intent(this, MainActivity.class);
//PendingIntent pendingIntent = new PendingIntent.getActivity(this, 0, notificationIntent, 0);

nManager.notify(noti_ID, nBuilder.build());

谢谢:)

来自developer.android.com

Required notification contents

A Notification object must contain the following:

A small icon, set by setSmallIcon()
A title, set by setContentTitle()
Detail text, set by setContentText()

所以也设置一个小图标。