Android创建通知栏
来源:互联网 发布:餐饮排队叫号软件 编辑:程序博客网 时间:2024/06/05 11:22
一般方法在下面:
/** * 创建通知栏进度条 * * @param mNotifyManager * @param mBuilder * @param context 上下文 * @param icon 图标 * @param title 标题 * @param contentText 信息 */ public static void createNotification(NotificationManager mNotifyManager, NotificationCompat.Builder mBuilder, Context context, int icon, String title, String contentText) {// mNotifyManager = (NotificationManager) context.getSystemService(NOTIFICATION_SERVICE);// mBuilder = new NotificationCompat.Builder(context); mBuilder.setSmallIcon(icon); mBuilder.setContentTitle(title); mBuilder.setContentText(contentText); mBuilder.setProgress(0, 0, false); mBuilder.setOngoing(true); //通知栏常驻 Notification notification = mBuilder.build();// -------------------------------Notification的Flag设置-------------------------// public static final int FLAG_SHOW_LIGHTS = 0x00000001;//控制闪光// public static final int FLAG_ONGOING_EVENT = 0x00000002;//将flag设置为这个属性, //那么通知就会像QQ一样一直在状态栏显示// public static final int FLAG_INSISTENT = 0x00000004; //重复发出声音, // 直到用户响应此通知// public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008;//标记声音或者震动一次// public static final int FLAG_AUTO_CANCEL = 0x00000010; //在通知栏上点击此通知 // 后自动清除此通知// public static final int FLAG_NO_CLEAR = 0x00000020;//将flag设置为这个属性 // 那么通知栏的那个清楚按钮就不会出现// public static final int FLAG_FOREGROUND_SERVICE = 0x00000040;//前台服务标记// public static final int FLAG_HIGH_PRIORITY = 0x00000080;// --------------------------------------------------------------------------------// notification.flags = Notification.FLAG_ONGOING_EVENT; mNotifyManager.notify(0, notification); } /** * 更新通知栏进度条 * * @param mNotifyManager * @param mBuilder * @param percent 百分比 * @param length 最大值 */ public static void notifyNotification(NotificationManager mNotifyManager, NotificationCompat.Builder mBuilder, long percent, long length) { mBuilder.setProgress((int) length, (int) percent, false); mNotifyManager.notify(0, mBuilder.build()); }
需要注意的一个问题是,当你更新通知栏里面进度条的进度时,不要太频繁,因为频繁更新会导致程序卡。你可以在子线程中处理这些事情。
阅读全文
0 0
- Android创建通知栏
- Android创建并更新通知栏通知
- android 创建通知栏Notification
- Android Notification通知栏的创建
- android 通知的创建
- Android通知栏通知
- Android 简单创建一条通知
- 简单创建Android状态栏通知
- Android创建通知栏Notification(使用新API)
- 【notification】Android 中创建震动通知
- 【notification】Android 中创建状态栏通知
- 【Android】利用服务Service创建标题栏通知
- 在Android Wear 上创建通知
- Android创建使用默认布局的通知
- Android 使用Notification创建推送通知
- Android 利用服务Service创建标题栏通知
- android通知栏进度条
- android 通知栏处理
- Python编程:从入门到实践(课后习题10)
- C++函数模板
- struts2有关通配符的总结,一个小万能的公式解决大问题
- Java 方法传参
- Web Dynpor 组件属性介绍
- Android创建通知栏
- (Android开发)ADB被占用,服务(Service)不能开启等情况记录与解决办法
- 参数化 ${参数名}
- C++易错知识点更新
- Linux下JDK、Tomcat的安装及配置
- Android权限问题整理
- Android todo-mvp
- Not supported by zabbix agent 问题解决
- spring的@Transactional详解