Android通知Notification

Notification的使用大体步骤:

1、 获取状态通知栏管理
2、 实例化通知栏构造器
3、 设置NotificationCompat.Builder
4、 设置PendingIntent
5、 显示
先附上一个实例化的代码:

/*setSmallIcon设置图标
setLargeIcon() 设置通知的大图标,当下拉通知后显示的图标。 
setWhen() 指定通知被创建的时间,以毫秒为单位,下拉通知后会将时间显示在相应的通知上。
*/

Notification notification = new NotificationCompat.Builder(Context)
            .setContentText("通知内容")
            .setContentTitle("通知标题")
            .setSmallIcon(android.R.mipmap.ic_launcher_round)
          .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher_round))
            .setWhen(System.currentTimeMillis())
            .build();

猜你喜欢

转载自blog.csdn.net/xfscy/article/details/80574603