Notification的理解及使用
2015-11-30 15:46
288 查看
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);;
Notification notification = new Notification();//创建一个notification对象
notification.icon = R.drawable.ic_log;//设置通知栏上的图标
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.tickerText = "开始下载";//设置通知栏上显示的内容
通知的默认参数DEFAULT_SOUND,DEFAULT_VIBRATE,DEFAULT_LIGHTS.
//如果要全部采用默认值,用DEFAULT_ALL.
//此处采用默认声音
notification.defaults=Notification.DEFAULT_SOUND;
使用自定义视图
remoteViews = new RemoteViews(getPackageName(), R.layout.test);
remoteViews.setImageViewResource(R.id.iv_down_load_icon,
R.drawable.ic_log);//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_app_name,
getResources().getString(R.string.app_name));//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_download_time,
CommonUtil.formatDateHour());//获取自定义视图上的控件并进行设置
notification.contentView = remoteViews;
Intent intentInstal = new Intent(UpdataService.this, InstallApkBroadcast.class);
intentInstal.putExtra("filepath", APKURL);
// intentInstal.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intentInstal.addCategory(Intent.CATEGORY_DEFAULT);
PendingIntent pi = PendingIntent.getBroadcast(UpdataService.this, 0,//开启一个广播
intentInstal, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.contentIntent = pi;
notificationManager.notify(NOTIFICATION_ID, notification);
Notification notification = new Notification();//创建一个notification对象
notification.icon = R.drawable.ic_log;//设置通知栏上的图标
notification.flags = Notification.FLAG_ONGOING_EVENT;
notification.tickerText = "开始下载";//设置通知栏上显示的内容
通知的默认参数DEFAULT_SOUND,DEFAULT_VIBRATE,DEFAULT_LIGHTS.
//如果要全部采用默认值,用DEFAULT_ALL.
//此处采用默认声音
notification.defaults=Notification.DEFAULT_SOUND;
使用自定义视图
remoteViews = new RemoteViews(getPackageName(), R.layout.test);
remoteViews.setImageViewResource(R.id.iv_down_load_icon,
R.drawable.ic_log);//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_app_name,
getResources().getString(R.string.app_name));//获取自定义视图上的控件并进行设置
remoteViews.setTextViewText(R.id.tv_download_time,
CommonUtil.formatDateHour());//获取自定义视图上的控件并进行设置
notification.contentView = remoteViews;
Intent intentInstal = new Intent(UpdataService.this, InstallApkBroadcast.class);
intentInstal.putExtra("filepath", APKURL);
// intentInstal.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// intentInstal.addCategory(Intent.CATEGORY_DEFAULT);
PendingIntent pi = PendingIntent.getBroadcast(UpdataService.this, 0,//开启一个广播
intentInstal, Intent.FLAG_ACTIVITY_NEW_TASK);
notification.contentIntent = pi;
notificationManager.notify(NOTIFICATION_ID, notification);
相关文章推荐
- Java调试信息输出
- IOS学习之多线程(5)--GCD介绍
- C语言_冒泡排序
- NSValue【转】
- 19、OSPF配置实验之注入默认路由
- 从Java类库看设计模式(1)
- ZPL实例说明
- Xcode 蓝色文件夹和黄色文件夹的区别
- C# 邮件发送注意事项
- Sql 执行删除修改之前添加备份
- c++字符串分词
- configure.ac范例二
- 用法总结:NSNumber、NSString、NSDate、NSCalendarDate、NSData
- 排序算法一:内部排序算法Python实现
- SQL Azure (16)创建PaaS SQL Azure V12数据库
- 干货:结合Scikit-learn介绍几种常用的特征选择方法
- 简单的网络爬虫
- delphi 读写文本
- OpenGL ES2.0 的三种变量类型(uniform,attribute和varying)
- Looking "Under the Hood" with javap