zoukankan      html  css  js  c++  java
  • 自定义Notification

    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);
        }
    
  • 相关阅读:
    用php获取本周,上周,本月,上月,本季度日期的代码
    PHP取整,四舍五入取整、向上取整、向下取整、小数截取
    图解phpstorm常用快捷键
    web安全之如何防止CSRF跨站请求伪造
    Ajax同步异步的区别
    php中文件上传需要注意的几点
    D4 HL 数据结构
    D3 HL 模拟赛订正
    D2 HL 图的高级应用 网络流专题
    D1 HL 图的高级应用 tarjan算法
  • 原文地址:https://www.cnblogs.com/0616--ataozhijia/p/3680957.html
Copyright © 2011-2022 走看看