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. udp内网穿透 两个内网互联

    1,在有外网ip的机器上启动server. package udp; import java.net.DatagramPacket; import java.net.InetSocketAddress ...

  2. Dedecms最新版本存储型XSS

    由于编辑文章的模板参数 typeid2可控,导致存储XSS发生. dedecms/dede/templets/article_edit.htm页面316-325行代码如下: <tr> &l ...

  3. Visual Studio Online Integrations

                                                                                                         ...

  4. WPF 检测计算机网络连接情况

    ; ; ; ; [DllImport("wininet.dll")] private extern static bool InternetGetConnectedState(ou ...

  5. 找出现有Vector或ArrayList或数组中重复的元素&给现有Vector或ArrayList或数组去重

    //直接上代码: public static void main(String[] args) { List<Integer> list = new Vector<Integer&g ...

  6. linux下面覆盖文件,如何实现直接覆盖,不提示

    转自:http://w-tingsheng.blog.163.com/blog/static/2505603420124309130528/ cp覆盖时,无论加什么参数-f之类的还是提示是否覆盖,当文 ...

  7. logback logback.xml常用配置详解(三)

    logback logback.xml常用配置详解 <filter> <filter>: 过滤器,执行一个过滤器会有返回个枚举值,即DENY,NEUTRAL,ACCEPT其中之 ...

  8. 不用插件直接同步wordpress文章日志到新浪微博

    社会化媒体营销可以为网站带来流量,如果你的社会化媒体账号的粉丝技术够大的话!社会化媒体营销国内做得比较好的算新浪微博了.那么我们要怎样同步wordpress文章日志到新浪微博呢?当然你可以使用插件来实 ...

  9. java类加载器

    1.什么是类加载器?类加载器实现什么功能? 类加载器(Class Loader)是用来加载java类到java虚拟机(JVM)中,加载步骤: java编译器编译java源文件(*.java文件)成字节 ...

  10. WPF 动画(形状、画刷)

    一:形状 在WPF用户界面中,可以通过形状(Shape)来绘制直线.椭圆.矩形及一些多边形的类.通过这些基本的图像,组合成为复杂的图形. Shape类中,主要的形状有Rectangle(),Ellip ...