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 ...
随机推荐
- vue:绑定数据的vue页面加载会闪烁问题
1:在挂在数据的容器加上属性 v-cloak 2:在css中添加如下代码 但有时候还是会不起作用,可能原因有两个 2.1:display属性被更高权限的display属性覆盖了,我们增加权限就好了 2 ...
- C++中类的多继承
在写这一主题的文章之前,在网上找到一篇很非常好的文章C++之继承与多态.就没有必要做重复造轮子的事件了,那就从这篇文章开始吧! 在c++中一个类可以从多个基类中派生(即可以有多个父类),这就是多继承. ...
- Haskell语言练习
Monad inc n = Just (n + 1) add1 n = [n + 1] main = do print $ Nothing >> (Just 0) -- Nothing p ...
- C++多态,虚函数,虚函数表,纯虚函数
1.多态性 指相同对象收到不同消息或不同对象收到相同消息时产生不同的实现动作. C++支持两种多态性:编译时多态性,运行时多态性. a.编译时多态性:通过重载函数实现 ,模板(2次编译) ...
- 连接mysql连接不上遇到的问题
连接不上mysql ,启动mysqld进程,发现可以启动成功,但几秒后进程立马关闭了,后来发现主要原因是因为磁盘空间满了. 报错: Can't connect to local MySQL serve ...
- 吴裕雄 python 机器学习-NBYS(2)
import matplotlib import numpy as np import matplotlib.pyplot as plt n = 1000 xcord0 = [] ycord0 = [ ...
- JAVA语言 第六周
时间太快了,过几天就要去学校了.在家里学习不下去,一点不心静.学习也不如刚放假的时候了. 活在被开学支配的恐惧下,每天看一会儿视频(书是真的难看下去). 效果不明显,这个暑假已经被拉开差距 了.提前几 ...
- vuex的几个细节
vuex中的state值一般是不能再外面修改的,如果开发者外面修改store里面的值就失去其存在的意义了,这里需要其加属性如下所示: const isDev = process.env.NODE_EN ...
- 如何区分Java中的方法重载和重写
首先说的是重载: 方法的重载 * 在同一个类中,方法名相同,参数列表不同.与返回值类型无关. * 参数列表不同: * A:参数个数不同 * B:参数类型不同 * C:参数的顺序不同(不算重载 报错) ...
- Avatar
[Avatar] 1.Retargeting of Humanoid animations Retargeting is only possible for humanoid models, wher ...