Android开发——Notification通知的使用及NotificationCopat.Builder常用设置API (7)

   BigPictureStyle 大图片显示

Intent intent = new Intent(this,Main2Activity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this,0,intent,0);
NotificationManager manger = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
Notification notification = new NotificationCompat.Builder(this)
.setContentTitle("this is cotenttitle")//设置标题,必要
.setContentText("contentText")//设置内容,必要
.setWhen(System.currentTimeMillis())//设置时间,默认设置,可以忽略
.setSmallIcon(R.mipmap.ic_launcher)//设置通知栏的小图标,必须设置
.setAutoCancel(true)//设置自动删除,点击通知栏信息之后系统会自动将状态栏的通知删除
.setContentIntent(pendingIntent)//设置在通知栏中点击该信息之后的跳转,参数是一个pendingIntent
     .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher))
     //设置大图标,未设置时使用小图标代替,拉下通知栏显示的那个图标
     //设置大图片 BitmpFactory.decodeResource(Resource res,int id) 根据给定的资源Id解析成位
     .setStyle(new NotificationCompat.BigPictureStyle().bigPicture(BitmapFactory.decodeResource(getResources(),R.drawable.index)))
     .build();
     manger.notify(1,notification);

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wpfdwd.html