android显示通知栏Notification以及自定义Notification的View
遇到的最大的问题是监听不到用户清除通知栏的广播。所以是不能监听到的。
自定义通知栏的View,然后service运行时更改notification的信息。
/**
* Show a notification while this service is running.
* 在service运行时,显示通知信息
*/
public void showNotification() {
NotificationManager mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
CharSequence text = getText(R.string.app_name);
Notification notification = new Notification(R.drawable.img_step_counter_user, null,
System.currentTimeMillis());
// 标志位的设置:应设置为可以自动取消,这样用户就可以取消他,如果设置为Intent.FLAG_ACTIVITY_CLEAR_TOP | Notification.FLAG_ONGOING_EVENT;则会一直显示通知
// notification.flags = Intent.FLAG_ACTIVITY_CLEAR_TOP | Notification.FLAG_ONGOING_EVENT;
notification.flags = Notification.FLAG_AUTO_CANCEL;
Intent pedometerIntent = new Intent();
pedometerIntent.setComponent(new ComponentName(this, StepCounterHomePageActivity.class));
pedometerIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
pedometerIntent, 0);
notification.setLatestEventInfo(this, text,
getText(R.string.notification_subtitle)+": "+SensorData.stepNum+" 步", contentIntent);
// 其中R.layout.notification是一个布局文件
notification.contentView = new RemoteViews(getPackageName(),R.layout.notification);
notification.contentView.setViewVisibility(R.id.usermessage, View.VISIBLE);
notification.contentView.setViewVisibility(R.id.notification_background, View.GONE);
notification.contentView.setViewVisibility(R.id.notification_layout, View.GONE);
notification.contentView.setTextViewText(R.id.tv_user_name_step, "掌上医生");
notification.contentView.setTextViewText(R.id.tv_use_date_step, "计算步数: "+SensorData.stepNum+"步"); mNM.notify(R.string.app_name, notification);
}
android显示通知栏Notification以及自定义Notification的View的更多相关文章
- Android学习(二十)Notification通知栏
一.通知栏的内容 1.图标 2.标题 3.内容 4.时间 5.点击后的相应 二.如何实现通知栏 1.获取NotificationManager. 2.显示通知栏:notify(id,notificat ...
- Android 主页面顶部栏的通知Notification ,可以自定义通知消息栏的风格,并且点击通知栏进人本程序。
常用的程序通知,显示到主页面的顶部栏. package com.lixu.tongzhi; import android.app.Activity; import android.app.Notifi ...
- android自定义Notification通知栏实例
项目有个需求,需要在发送Notification的时候动态给定url的图片.大概思路如下:自己定义一个Notification的布局文件,这样能够很方便设置View的属性. 首先加载网络图片,使用Bi ...
- Android自定义Notification并没有那么简单
背景 最近需要实现一个自定义Notification的功能.网上找了找代码,解决方案就是通过RemoteViews来实现.但是在实现过程中遇到不少问题,网上也没有很好的文章描述这些问题,所以在这里做个 ...
- Android -- 系统和自定义Notification
Notification是一种让你的应用程序在不使用Activity的情况下警示用户,Notification是看不见的程序组件警示用户有需要注意的事件发生的最好途径. 作为UI部分,Notifica ...
- Android为TV端助力 自定义通知栏
package com.example.mvp; import cn.ljuns.temperature.view.TemperatureView;import presenter.ILoginPre ...
- 自定义Notification
private static void updateProgressNotification(Context cxt, int appsCount, int percent, String appNa ...
- 强烈推荐:Android史上最强大的自定义任务软件Tasker
强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ...
- android的通知栏的实现
package com.example.mynotification; import android.os.Bundle; import android.app.Activity; import an ...
随机推荐
- ACM__容器之vector
今天做题碰到了深搜的题,有一种存图方式需要用到vector,对vector不是很熟悉,回顾了一下 vector都知道是一个容器,但并不准确,它是一个多功能的能够操作多种数据结构和算法的模板类和函数库. ...
- laravel视图$errors为空
最近用laravel5.2的validator时,完全参考手册操作,结果控制器$validator->errors()->all()正常显示错误信息,$validator->fail ...
- 记一个pg连接数过多的异常
java中使用数据库连接池,如果在部署的时候,操作不慎,可能出现典型的连接池爆满的问题 org.postgresql.util.PSQLException: FATAL: sorry, too man ...
- [Linux]Ubuntu下安装Sublime-text 且 支持中文输入
------------------------------------------------------------------------------------------ 首先进行如下操作: ...
- Android DevArt6:Android中IPC的六种方式
Android中IPC的六种方式 1.使用Bundle 最简单的进程间通信方式:Intent + Bundle: 支持三大组件:Activity.Service.BroadcastReceiver : ...
- SQLServer 的数据分页:
假设现在有这样的一张表:CREATE TABLE test( id int primary key not null identity, names varchar(20))然后向里面插入大约1000 ...
- ArcGIS中的WKID(转)
ArcGIS中的WKID link: https://www.cnblogs.com/liweis/p/5951032.html 提到坐标系统,大家多少能明白一些,但在运用时,有些朋友搞得不是非常清楚 ...
- DOS批量拷贝本地目录到远程主机(定时执行)
echo !USER! net use \\!REMOTE_ADDR!\IPC$ /u:!USER! copy D:\batch\ip.bat \\!REMOTE_ADDR!\Admin$\ / ...
- [转载]FMS Dev Guide学习笔记(验证用户)
一.开发交互式的媒体应用程序 1.使用外部资源验证用户 对于有限数量的客户,请求用户名密码,然后通过外部资源(像数据库.LDAP服务或其它访问授权服务)验证它们,是可行的. a.SWF在请求连 ...
- servlet、servlet容器和web应用程序的关系