博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
自定义Notification
阅读量:7063 次
发布时间:2019-06-28

本文共 1968 字,大约阅读时间需要 6 分钟。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
private 
static 
void 
updateProgressNotification(Context cxt, 
int 
appsCount,
            
int 
percent, String appName, 
boolean 
showTicker) {
        
NotificationManager nm = (NotificationManager) cxt.getSystemService(
                
Context.NOTIFICATION_SERVICE);
        
if 
(DEBUG) LogHelper.d(TAG, 
"update notification: " 
+ appsCount + 
", appName: " 
+ appName);
        
if 
(appsCount == 
0
) {
            
nm.cancel(Constants.STATUSBAR_APK_DOWNLOADER_PROGRESS_ID);
            
return
;
        
}
 
        
String status = 
null
;
        
if 
(appsCount == 
1
) {
            
status = cxt.getString(Res.string.download_notification_downloading_one, appName);
        
else 
{
            
status = cxt.getString(Res.string.download_notification_downloading_more, appsCount);
        
}
 
        
RemoteViews downloadView = 
new 
RemoteViews(Constants.REAL_PACKAGE_NAME,
                
Res.layout.notification_apkdownloader_downloading);
        
downloadView.setTextViewText(Res.id.title, status);
        
downloadView.setProgressBar(Res.id.progress_bar, 
100
, percent, 
false
);
 
        
Intent intent = 
new 
Intent(cxt, DownloadMgrActivity.
class
);
        
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        
PendingIntent pi = PendingIntent.getActivity(cxt, 
0
, intent,
                
PendingIntent.FLAG_UPDATE_CURRENT);
 
        
Notification notification = 
new 
Notification();
        
notification.icon = NotificationUtils.getGroupIconIdByGroupId(Constants.NOTIFICATION_APPGROUP, Constants.STATE_GREEN);
        
notification.when = 
0
;
        
notification.flags = Notification.FLAG_ONGOING_EVENT;
        
notification.defaults = 
0
;
        
notification.sound = 
null
;
        
notification.vibrate = 
null
;
        
notification.contentView = downloadView;
        
notification.contentIntent = pi;
        
if 
(showTicker) {
            
String ticker = cxt.getString(Res.string.download_notification_downloading_one, appName);
            
notification.tickerText = ticker;
        
}
 
        
nm.notify(Constants.STATUSBAR_APK_DOWNLOADER_PROGRESS_ID, notification);
    
}

 本文转自demoblog博客园博客,原文链接http://www.cnblogs.com/0616--ataozhijia/p/3680957.html如需转载请自行联系原作者

demoblog

你可能感兴趣的文章
NotePad++ for PHP
查看>>
ssh事务回滚,纪念这几个月困扰已久的心酸
查看>>
jQuery中的编程范式
查看>>
比较快速排序,冒泡排序,双向冒泡排序的执行效率
查看>>
还没被玩坏的robobrowser(5)——Beautiful Soup的过滤器
查看>>
Linux 精准获取进程pid--转
查看>>
Servlet、Filter、Listener总结
查看>>
[翻译] JTBorderDotAnimation
查看>>
关于Thread类中三个interrupt方法的研究与学习(转)
查看>>
mysql 加入列,改动列,删除列。
查看>>
UML的学习
查看>>
ContentProvider简单介绍
查看>>
SQL SERVER获取数据库中所有表名 XTYPE类型
查看>>
java设计模式3--单例模式(Singleton)
查看>>
C#开发微信门户及应用(27)-公众号模板消息管理
查看>>
Java日志最佳实践
查看>>
【Active入门】ActiveMQ学习-1
查看>>
Hibernate查询语言
查看>>
能在CAD2004以下版本里面打开2007以上版本文件的外挂
查看>>
linux定时调度器每秒运行一次
查看>>