在Android中Notification用于显示状态栏通知,例如消息提示或者保持某种状态的提示等场景,为方便使用,简单记录下Notification的使用步骤:
一 、获取NotificationManager
NotificationManager mNotifyManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
二、创建Notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setContentTitle("服务通知")//设置通知标题
.setContentText("这是一个服务通知")//设置通知内容
.setSmallIcon(R.mipmap.ic_launcher);//设置通知图标
三、发送通知
//参数1为通知的唯一标识
mNotifyManager.notify(1,builder.build());