Notification的简单使用

来源:互联网 发布:360软件修补漏洞 编辑:程序博客网 时间:2024/06/05 15:26

Notification是Android中通知栏内容的控件,我们可以使用Notification在通知栏显示要提示给用户的消息。
下面是一段简单的代码

 private static final int NOTIFICATION_ID = 1; //NOTIFICATION_ID是用来标识Notification的 NotificationCompat.Builder builder = new NotificationCompat.Builder(MainActivity.this); //使用builder来创建Notification  builder.setSmallIcon(R.mipmap.ic_launcher);  //设置图标 builder.setContentTitle("新消息"); builder.setContentText("这是你收到的新消息的内容"); Notification notification = builder.build();  //创建Notification对象 NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.notify(NOTIFICATION_ID,notification);

这里写图片描述

0 0
原创粉丝点击