Android灯光系统--通知灯深入分析【转】
本文转自:https://www.cnblogs.com/lkq1220/p/6406261.html
Android灯光系统--通知灯深入分析
通知的类别
声音
振动
闪灯
APP如何发出通知灯请求
getSystemService(获得通知服务)
构造notification
类别
其他参数(颜色,onMS,offMS)
发出通知
系统如何处理
启动通知Service
收到通知之后
分辨通知类型
执行响应操作
对于通知灯
获得LightService
执行灯光相关操作
APP如何获得通知服务
ContextImp:resigsterService
返回一个NotificationManager对象
构造Notification
NotificationManager.notify()将通知发送出去
发送通知之后如何调用通知灯
Service=getService() //获得某个服务
注册有Notification服务
根据名字Notification获得Service服务
Service.enqueueNotificationwithTag //放入通知队列
通过enqueueNotificationwithTag中的buzzBeepBlinkLocked判断是否是属于哪种通知类别
获得通知属于闪灯,调用updateLightsLocked()
取出notification当中的参数,调用mNotificationLights类当中的setFlashing
注册LightManager服务
根据ID从LightManager中返回获取mNotificationLights类
编写模拟通知灯安卓程序
定义按钮,控制20S之后熄屏亮灯
定义Flashing boolean型变量,用于控制按钮操作
设置按钮响应函数--判断按钮操作,改变按钮text值,并且发出通知
构造通知执行方法 - 实现Runnable接口方法
获得按钮状态
调用开通知灯函数
获得通知服务
构造通知,设置参数
发送通知
关闭通知灯函数
获得通知服务
取消通知灯服务
通知
- 延迟20S通知调用postDelayed函数
附上详细代码:
package com.example.alienware.app_0002_lightdemo;
import android.app.Notification;
import android.app.NotificationManager;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
/*
* 模拟熄屏时候,短信等通知发生时候,通知灯亮起
* 设置屏幕背光亮时间为15s,才可以进行下列实验
* Date:2017.2.16 Author:LKQ
* 代码原创者:韦东山老师
*/
public class MainActivity extends AppCompatActivity {
private Button mLightButton = null;
boolean Flashing = false;
final private int LED_NOTIFICATION_ID = 109;
private Handler mLightHandler = new Handler();
private LightRunnable mLightRunnable = new LightRunnable();
//实现消息通知后的执行方法
class LightRunnable implements Runnable{
@Override
public void run() {
if(Flashing){
BlueFlashLight(); //蓝灯闪亮
}
else{
ClearLED(); //关闭通知灯
}
}
}
private void BlueFlashLight()
{
NotificationManager nm = (NotificationManager)getSystemService( NOTIFICATION_SERVICE ); //获取通知服务
Notification notif = new Notification(); //构造通知类型
notif.flags = Notification.FLAG_SHOW_LIGHTS; //设置通知类型为通知灯
notif.ledARGB = 0xFF0000ff; //颜色
notif.ledOnMS = 1000;
notif.ledOffMS = 1000; //闪烁时间为1S
nm.notify(LED_NOTIFICATION_ID, notif); //发送通知
}
private void ClearLED()
{
NotificationManager nm = ( NotificationManager ) getSystemService( NOTIFICATION_SERVICE );
nm.cancel( LED_NOTIFICATION_ID ); //关闭通知灯
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mLightButton = (Button)findViewById(R.id.button);
mLightButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
Flashing = !Flashing;
if (Flashing) {
mLightButton.setText("Stop Flashing the Light !");
} else {
mLightButton.setText("Flashing Light at 20S");
}
mLightHandler.postDelayed(mLightRunnable, 20000); //20S之后,即是熄屏时候,通知灯闪烁
}
});
}
}
Android灯光系统--通知灯深入分析【转】的更多相关文章
- Android灯光系统--通知灯深入分析
Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(获得通知服务) 构造notification 类别 其他参数(颜色, ...
- Android系统之灯光系统--通知灯深入分析
Android通知灯的深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(通知服务) 构造notification 类别 其他参数(颜色,onMS,of ...
- 8.5 Android灯光系统_源码分析_通知灯
参考文章(应用程序举例)how to use the LED with Android phonehttp://androidblogger.blogspot.jp/2009/09/tutorial- ...
- 【转】Android中通知的提示音、震动和LED灯效果小例子
通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现.发出一条通知后,手机最上方 ...
- Android灯光系统--深入理解背光灯
Android灯光系统--深入理解背光灯 一.怎么控制背光灯(简述) APP将亮度值写入数据库 线程检测数据库的值是否发生变化 这种机制成为"内容观察者"--contentObse ...
- Android灯光系统_编写HAL_lights.c【转】
本文转载自:https://blog.csdn.net/qq_33443989/article/details/77074411 1>. 编写灯光系统的HAL层 之 HAL_light.c1&l ...
- 8.1 Android灯光系统_总体框架
1.框架 APP(java语言实现) ------------------------------- JNI(c++语言实现) 向上提供Java执行c函数的接口 向下访问HAL ------ ...
- android: 使用通知
8.1 使用通知 通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向 用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现.发 ...
- Android消息通知(notification)和PendingIntent传值
通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...
随机推荐
- 2. Python3输入与输出
数据的输入和输出操作是计算机最基本的操作,本节只研究基本的输入与输出,基本输入是指从键盘上输入数据的操作,基本输出是指屏幕上显示输出结果的操作. 2.1基本输入和输出 常用的输入与输出设备有很多,如摄 ...
- [6]传奇3服务器源码分析一GameGate
1. 2. 留存 服务端下载地址: 点击这里
- VMWare虚拟机 window文件传递
无论是将虚拟机的文件传到window上或者是将window上文件传到虚拟机上: 都可以选中文件,然后拖动文件到另一个系统上 提前:虚拟机安装了VMWARE Tools 1)window上文件拖到虚拟机 ...
- 准备mysql-connector-java
下载mysql-connector-java:https://mvnrepository.com/artifact/mysql/mysql-connector-java 导入mysql-connect ...
- Sql日期时间格式转换[zhuan]
sql server2000中使用convert来取得datetime数据类型样式(全) 日期数据格式的处理,两个示例: CONVERT(varchar(16), 时间一, 20) 结果:2007-0 ...
- Win7 Python开发环境搭建
1. 下载Anaconda并安装 地址: https://www.anaconda.com/download/ Anaconda包括Python基础包与一系列科学计算包,安装后不用再单独安装Pyth ...
- 【Alpha版本】冲刺阶段——Day4
[Alpha版本]冲刺阶段--Day4 阅读目录 今日进展 问题困难 明日任务 今日贡献量 TODOlist [今日进展] 完成注册类代码 public class Register { privat ...
- php Allocator Jemalloc TCMalloc那个内存分配器比较好?
php Allocator Jemalloc TCMalloc那个内存分配器比较好? php一键安装脚本可以选择是否安装内存优化 You have 3 options for your Memory ...
- jQuery的ajaxFileUpload上传插件——刷新一次才能再次调用触发change
这个问题并不是由change事件失效造成的,而是ajaxFileUpload插件造成的,它会把原来的file元素替换成新的file元素,所以之前绑定的change事件就失效了. 查了一些资料,有些朋友 ...
- linux OS与SQL修改时区,系统时间
linux修改系统时间和linux查看时区.修改时区的方法 一.查看和修改Linux的时区 1. 查看当前时区命令 : "date -R" 2. 修改设置Linux服务器时区方法 ...