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

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

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);    }

 

转载地址:http://pdgwo.baihongyu.com/

你可能感兴趣的文章
PHP坑之积累
查看>>
POJ3304:Segments——题解
查看>>
48.EXt.Data.JsonReader()
查看>>
Jquery的toggle()与trigger()方法
查看>>
UML关系图
查看>>
Spring事务隔离级别,事务传播行为
查看>>
一个action读取另一个action里的session
查看>>
NSDate NSDateFormatter
查看>>
oralce中rownum理解
查看>>
leetcode 175. Combine Two Tables
查看>>
C#/ASP.NET完善的DBHelper,配套Model生成器
查看>>
如何给一个数组对象去重
查看>>
Guava包学习-Cache
查看>>
分享打造爆款书的方法,同时聊聊出版图书中的哪些事和哪些坑
查看>>
第8周作业
查看>>
2019-06-12 Java学习日记之JDBC
查看>>
灯箱效果(点击小图 弹出大图集 然后轮播)
查看>>
linux c 笔记 线程控制(二)
查看>>
samba服务器配置
查看>>
SpringMVC+Apache Shiro+JPA(hibernate)整合配置
查看>>