简单记录 通知上的设置方法,没有示例
//进度 通知
notificationManager = (NotificationManager)
context.getSystemService(Context.NOTIFICATION_SERVICE);
builder = new NotificationCompat.Builder(context);
builder.setContentTitle("新版本")//显示的标题
.setContentText("正在下载...")//显示的详细内容
.setSmallIcon(R.mipmap.ic_launcher);
//提示文字
builder.setTicker("您有新消息!");
//点击取消,优先级
builder.setAutoCancel(true).
setPriority(NotificationCompat.PRIORITY_DEFAULT);
builder.setDefaults(Notification.DEFAULT_ALL);
// 关联PendingIntent,点击跳转的页面
//PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
// new Intent(this, MainActivity.class), 0);
//builder.setContentIntent();
//指定视图Notification 正常状态下的视图
// builder.build().contentView=contentView;
//展开时的视图
//builder.build().bigContentView = expandView;
/*提示方式
DEFAULT_ALL:铃声、闪光、震动均系统默认。
DEFAULT_SOUND:系统默认铃声。
DEFAULT_VIBRATE:系统默认震动。
DEFAULT_LIGHTS:系统默认闪光。
其他方式:
setSound(Uri sound):设定一个铃声,用于在通知的时候响应。
传递一个Uri的参数,格式为“file:///mnt/sdcard/Xxx.mp3”。
setLights(int argb, int onMs, int offMs):设定前置LED灯的闪烁速率,
持续毫秒数,停顿毫秒数。
setVibrate(long[] pattern):设定震动的模式,以一个long数组保存毫秒级间隔的震动。
*/
/*
setStyle()传递一个NotificationCompat.Style对象,它是一个抽象类,
Android为我们提供了三个实现类,用于显示不同的场景。分别是:
NotificationCompat.BigPictureStyle, 在细节部分显示一个256dp高度的位图。
NotificationCompat.BigTextStyle,在细节部分显示一个大的文本块。
NotificationCompat.InboxStyle,在细节部分显示一段行文本。*/
//builder.setWhen();//设置通知的时间,默认当前时间
发送通知:
//更新进度
builder.setProgress((int) l, (int) l1, true);
//发送通知
notificationManager.notify(notificationFlag, builder.build());
取消通知:
notificationManager.cancel(notificationFlag);