setLatestEventInfo 高版本替换
来源:互联网 发布:java清除缓存代码 编辑:程序博客网 时间:2024/05/21 20:29
setLatestEventInfo定义
public void setLatestEventInfo(Context context,
CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) {Notification.Builder builder = new Notification.Builder(context);
// First, ensure that key pieces of information that may have been set directly
// are preserved
builder.setWhen(this.when);
builder.setSmallIcon(this.icon);
builder.setPriority(this.priority);
builder.setTicker(this.tickerText);
builder.setNumber(this.number);
builder.setColor(this.color);
builder.mFlags = this.flags;
builder.setSound(this.sound, this.audioStreamType);
builder.setDefaults(this.defaults);
builder.setVibrate(this.vibrate);
// now apply the latestEventInfo fields
if (contentTitle != null) {
builder.setContentTitle(contentTitle);
}
if (contentText != null) {
builder.setContentText(contentText);
}
builder.setContentIntent(contentIntent);
builder.buildInto(this);
}
setLatestEventInfo方法仅适用于API22以下版本,API22以下可使用如下方法消息推送
// 1 得到通知管理器
NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// 2构建通知
Notification notification = new Notification(
R.drawable.ic_launcher, content,
System.currentTimeMillis());
// 3设置通知的点击事件
Intent resultIntent = new Intent(context, SplashActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(mContext, 100,
resultIntent, 0);
// notification.setLatestEventInfo(context, title, content , contentIntent);
notification.flags = Notification.FLAG_AUTO_CANCEL;// 点击通知之后自动消失
//清除 mediaNF
nm.cancel(99);
// 4发送通知
nm.notify(99, notification);
API 23以上版本 可使用如下方法替换
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//新建一个Notification管理器;
//API level 11
Notification.Builder builder = new Notification.Builder(context);//新建Notification.Builder对象
PendingIntent intent = PendingIntent.getActivity(context, 0, new Intent(context, SplashActivity.class), 0);
//PendingIntent点击通知后所跳转的页面
builder.setContentTitle(title);
builder.setContentText(content);
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentIntent(intent);//执行intent
Notification notification = builder.getNotification();//将builder对象转换为普通的notification
// builder.setUrl("http://www.nnhsart.com");//跳转URL
//API level 16以上
Notification notification = new Notification.Builder(context)
.setAutoCancel(true)
.setContentTitle("title")
.setContentText("describe")
.setContentIntent(intent )
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;//点击通知后通知消失
//清除 mediaNF
manager.cancel(100);
//发送通知
manager.notify(100, notification);
- setLatestEventInfo 高版本替换
- 全新的Android通知栏,已抛弃setLatestEventInfo,兼容高版本
- setLatestEventInfo
- setLatestEventInfo
- setLatestEventInfo
- setLatestEventInfo
- setLatestEventInfo
- 高版本chrome不再支持window.showmodaldialog 的临时替换方案【用window.open】
- Notification用法,注意API版本,API大于11的setLatestEventInfo()方法已经不适用
- 手动替换GCC版本
- make版本替换
- make版本替换
- Release版本 替换掉NSLog
- 字符串替换各语言版本
- 低版本编译兼容高版本版本
- ie 高版本兼容
- Android Notification.setLatestEventInfo(...)
- Notifiacation/setLatestEventInfo deprecated
- 蓝桥杯 分解质因数(模板)
- 微信开发-初级接入微信公众平台MP
- ZOJ 1093-Monkey and Banana
- jsp中错误页面处理的跳转问题
- pandas练习
- setLatestEventInfo 高版本替换
- C++中字符串匹配算法strstr()函数用法
- Java内存泄漏详解
- 一个创建用户的简单的shell脚本
- java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
- Mysql数据库将同一表中的A字段数据复制到B字段
- JSP页面中外部文件路径,AJAX的请求地址(:url)到底该怎么写呢?
- 学生表查询
- opencv图像分割