完成通知的描述后,您必须调用方法 build()。查看Android 参考以获取示例。
基本上,您必须将代码更改为以下内容:
Context context = getApplicationContext();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context )
.setSmallIcon(R.drawable.ic_launcher);
Intent intent = new Intent( context, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(context, mID , intent, 0);
builder.setContentIntent(pIntent);
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notif = builder.build();
mNotificationManager.notify(mID, notif);
注意:此代码仅允许在通知栏中显示您的图标。如果您希望它在那里持续存在,则必须使用FLAG_ONGOING_EVENT