遇到的最大的问题是监听不到用户清除通知栏的广播。所以是不能监听到的。

自定义通知栏的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的更多相关文章

  1. Android学习(二十)Notification通知栏

    一.通知栏的内容 1.图标 2.标题 3.内容 4.时间 5.点击后的相应 二.如何实现通知栏 1.获取NotificationManager. 2.显示通知栏:notify(id,notificat ...

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

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

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

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

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

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

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

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

  6. Android为TV端助力 自定义通知栏

    package com.example.mvp; import cn.ljuns.temperature.view.TemperatureView;import presenter.ILoginPre ...

  7. 自定义Notification

    private static void updateProgressNotification(Context cxt, int appsCount, int percent, String appNa ...

  8. 强烈推荐:Android史上最强大的自定义任务软件Tasker

    强烈推荐:Android史上最强大的自定义任务软件Taskerhttp://bbs.mumayi.com/thread-28387-1-1.html(出处: 木蚂蚁手机乐园) Android上的Tas ...

  9. android的通知栏的实现

    package com.example.mynotification; import android.os.Bundle; import android.app.Activity; import an ...

随机推荐

  1. python中函数基础

    函数 什么是函数? 函数分为内置函数和自定义函数 定义:在程序中具备某一功能的工具.在使用之前需准备该工具(函数的定义),遇到应用场景拿来就用(后引用). 为什么要用函数? 1.代码冗余 程序组织结构 ...

  2. oracle第三天笔记

    DDL语句管理表 /* Oracle体系结构: 数据库 ---> 数据库实例ORCL ---> 表空间 (用户里面的创建表) ---> 数据文件 地球 ---> 中国 ---& ...

  3. Java IO流学习总结五:转换流-InputStreamReader、OutputStreamWriter

    类的继承关系 Reader |__ BufferedReader.StringReader.InputStreamReader |__ FileReader Writer |__ BufferedWr ...

  4. ajax分页代码

    <meta charset="utf-8"><?php//连接数据库$link = mysqli_connect('127.0.0.1','root','root ...

  5. Swift字符串常用方法

    1.0 比较两个字符串是否相等 判断字符串相等的方法是: ==. var str1 = "Hello world" var str2 = "Hello world&quo ...

  6. JS----addEventListener()

    addEventListener() 用于向指定元素添加事件. 可以向一个元素添加多次事件或者多次不同事件,后面的事件是不会覆盖前面的. 语法: element.addEventListener(ev ...

  7. PHP源码安装经常会碰到的问题及解决办法

    错误:configure: error: freetype-config not found. 解决:yum install freetype-devel 错误:configure: error: l ...

  8. array_column 低版本兼容

    function i_array_column($input, $columnKey, $indexKey=null){ if(!function_exists('array_column')){ $ ...

  9. centos7里面docker不能下载本地源

    报这种错的 编辑这个文件 加上这一段内容 rstart重启,搞定.

  10. Python str list to list

    eg1: My csv data like this below,i wt count list nums 2018上,"['C', 'B', 'B', 'B', 'D', 'A', 'B' ...