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

自定义Notification的更多相关文章

  1. Android自定义Notification并没有那么简单

    背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...

  2. Android -- 系统和自定义Notification

    Notification是一种让你的应用程序在不使用Activity的情况下警示用户,Notification是看不见的程序组件警示用户有需要注意的事件发生的最好途径. 作为UI部分,Notifica ...

  3. android:使用RemoteView自定义Notification

    //网上相关内容较少,遂记录下来,备忘. //依然以音乐播放器demo为例. 效果截图 //锤子手机上的效果 step1 准备自定义layout 常规的实现方式,并不会因为是用于notificatio ...

  4. android自定义Notification通知栏实例

    项目有个需求,需要在发送Notification的时候动态给定url的图片.大概思路如下:自己定义一个Notification的布局文件,这样能够很方便设置View的属性. 首先加载网络图片,使用Bi ...

  5. android显示通知栏Notification以及自定义Notification的View

    遇到的最大的问题是监听不到用户清除通知栏的广播.所以是不能监听到的. 自定义通知栏的View,然后service运行时更改notification的信息. /** * Show a notificat ...

  6. 自定义Notification实现例子

    1.自定义view: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:a ...

  7. Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。

    常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...

  8. Notification的基本用法以及使用RemoteView实现自定义布局

    Notification的作用 Notification是一种全局效果的通知,在系统的通知栏中显示.既然作为通知,其基本作用有: 显示接收到短消息.即时信息等 显示客户端的推送(广告.优惠.新闻等) ...

  9. Android notification的使用

    notification出现在通知栏中的提示,特别是在4.0以后改进了不少,这里讲得都是基于4.0及4.1以后的. 分类: 1.普通Notification 2.大布局Notification 图1 ...

随机推荐

  1. Python之MySQL

    本文我们为大家介绍 Python3 使用 PyMySQL 连接数据库,并实现简单的增删改查. 什么是 PyMySQL? PyMySQL 是在 Python3.x 版本中用于连接 MySQL 服务器的一 ...

  2. Selenium2+python自动化13-Alert

    不是所有的弹出框都叫alert,在使用alert方法前,先要识别出它到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决.alert\confirm\prompt弹出框 ...

  3. std::thread join和detach区别

    thread detach, join 线程有两种状态,joinable或者detachable,pthread默认创建的线程是joinable的,也可以指定atrribute创建成一个detacha ...

  4. JDBCTemplate基础学习

    JDBCTemplate:spring提供的用于操作数据库的模板,类似DbUtils.使用时必须设置数据源(DataSource):数据源如DBCP.C3P0等 一.JDBCAPI简单使用Demo 1 ...

  5. Protocol Buffer技术详解(语言规范)

    Protocol Buffer技术详解(语言规范) 该系列Blog的内容主体主要源自于Protocol Buffer的官方文档,而代码示例则抽取于当前正在开发的一个公司内部项目的Demo.这样做的目的 ...

  6. 织梦DedeCms调用全站相关文章方法

    织梦DedeCms 有个标签可以调用相关文章,通过下面的修改可以调用全站的相关文章,文章页内显示相关文章内容,可以提高关键词密度,还是挺不错的. 模板调用代码 <div>     < ...

  7. 仿51job.com城市选择框特效

    650) this.width=650;" border="0" alt="" src="http://img1.51cto.com/att ...

  8. 统一软件开发过程(rup)理解

    不好意思,没有内容,请看百科吧http://baike.baidu.com/link?url=-zXA6oXiHRts5Z1THGzie7seH-YRigfiR7KRppP6TYcnnb7_Bxc_f ...

  9. VirtualBox下安装rhel5.5 linux系统

    以前也用过VMware server和VMware workstation虚拟机,现在使用了一段时间VirtualBox,感觉它比较轻巧,很适合我,在Win7系统下用起来很方便.下面详细介绍下在Vir ...

  10. Java开源数据库管理工具

    SQuirreL SQL Client   SQuirreL SQL Client 是一个用 Java 编写的程序,它允许您查看数据库的内容.发出 SQL 命令,以及如您将看到的,执行许多其他功能.构 ...