小白日记——下载进度的顶部通知
来源:互联网 发布:老实男人知乎 编辑:程序博客网 时间:2024/04/28 09:32
技术小白,把学到的觉得有用的东西放在上面,希望不要见笑。如果需要,欢迎转载。
带有进度条的顶部通知
声明全局变量
private PendingIntent pendingIntent;private NotificationManager notificationManager = null;private NotificationCompat.Builder builder;
在使用的地方实例化
notificationManager = (NotificationManager) .getSystemService(Context.NOTIFICATION_SERVICE);builder = new NotificationCompat.Builder(this);Intent intent = new Intent(this, NetActivity.class);pendingIntent = PendingIntent.getActivity(this, 1, intent, PendingIntent.FLAG_ONE_SHOT);
设置顶部通知的样式
builder.setSmallIcon(R.mipmap.ic_launcher);builder.setContentTitle("下载顶部通知");builder.setContentText("带有进度条的顶部通知,增加用户体验度");
程序演示,模拟进度条进度
new Thread(new Runnable(){ @Override public void run() { for (int i = 0; i <= 100; i++) { builder.setProgress(100, i, false); notificationManager.notify(13, builder.build()); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } builder.setContentText("下载完毕"); notificationManager.notify(14, builder.build()); notificationManager.cancel(13); } }).start();
刚刚学习使用MarkDown编辑器,勿喷,谢谢
0 0
- 小白日记——下载进度的顶部通知
- 阿了嗝欢的小白日记——HashMap(上)
- 小白日记
- 小白日记
- 小白日记 (2)
- linux小白日记
- 阿了嗝欢的小白日记——No session异常的发生原因和解决方案
- 小白日记第一天
- [UWP小白日记-8]一些零碎的东西
- Android——下载apk文件,并在通知栏显示下载进度
- echarts3.0在加载省市地图——小白日记
- 通知栏显示下载进度
- 下载进度的监听和通知的处理
- linux小白日记-C语言篇
- NotificationDownLoad 通知栏显示下载进度
- Android下载,在通知栏更新进度
- android 通知栏显示下载进度
- 一个APP下载升级的Demo(通知栏实时更新下载进度)------(一)
- 计算Label高度swift
- _snprintf_s, _snprintf_s_l, _snwprintf_s, _snwprintf_s_l
- VS2015 快捷键
- mxnet im2re.py
- mybatis xml中的小于的写法,like模糊查询的写法
- 小白日记——下载进度的顶部通知
- 第九章 Spring多线程处理
- Thrift入门初探--thrift安装及java入门实例
- 函数式编程扫盲
- struct usb_config_descriptor
- 一、java获取公网ip和本地ip
- SLAM:飞行机器人的参数解析-分类
- 第十章 Spring计划任务
- 深入理解拉格朗日乘子法(Lagrange Multiplier) 和KKT条件