Android灯光系统--通知灯深入分析

通知的类别

  • 声音

  • 振动

  • 闪灯

APP如何发出通知灯请求

  1. getSystemService(获得通知服务)

  2. 构造notification

    • 类别

    • 其他参数(颜色,onMS,offMS)

  3. 发出通知

系统如何处理

  1. 启动通知Service

  2. 收到通知之后

    • 分辨通知类型

    • 执行响应操作

  3. 对于通知灯

    • 获得LightService

    • 执行灯光相关操作

APP如何获得通知服务

  1. ContextImp:resigsterService

  2. 返回一个NotificationManager对象

  3. 构造Notification

  4. NotificationManager.notify()将通知发送出去

发送通知之后如何调用通知灯

  1. Service=getService() //获得某个服务

    • 注册有Notification服务

    • 根据名字Notification获得Service服务

  2. Service.enqueueNotificationwithTag //放入通知队列

  3. 通过enqueueNotificationwithTag中的buzzBeepBlinkLocked判断是否是属于哪种通知类别

  4. 获得通知属于闪灯,调用updateLightsLocked()

  5. 取出notification当中的参数,调用mNotificationLights类当中的setFlashing

    • 注册LightManager服务

    • 根据ID从LightManager中返回获取mNotificationLights类

编写模拟通知灯安卓程序

  1. 定义按钮,控制20S之后熄屏亮灯

    • 定义Flashing boolean型变量,用于控制按钮操作

    • 设置按钮响应函数--判断按钮操作,改变按钮text值,并且发出通知

  2. 构造通知执行方法 - 实现Runnable接口方法

    • 获得按钮状态

      • 调用开通知灯函数

      • 获得通知服务

      • 构造通知,设置参数

      • 发送通知

    • 关闭通知灯函数

      • 获得通知服务

      • 取消通知灯服务

  3. 通知

    • 延迟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灯光系统--通知灯深入分析的更多相关文章

  1. Android灯光系统--通知灯深入分析【转】

    本文转自:https://www.cnblogs.com/lkq1220/p/6406261.html Android灯光系统--通知灯深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 ...

  2. Android系统之灯光系统--通知灯深入分析

    Android通知灯的深入分析 通知的类别 声音 振动 闪灯 APP如何发出通知灯请求 getSystemService(通知服务) 构造notification 类别 其他参数(颜色,onMS,of ...

  3. 8.5 Android灯光系统_源码分析_通知灯

    参考文章(应用程序举例)how to use the LED with Android phonehttp://androidblogger.blogspot.jp/2009/09/tutorial- ...

  4. 【转】Android中通知的提示音、震动和LED灯效果小例子

    通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现.发出一条通知后,手机最上方 ...

  5. Android灯光系统--深入理解背光灯

    Android灯光系统--深入理解背光灯 一.怎么控制背光灯(简述) APP将亮度值写入数据库 线程检测数据库的值是否发生变化 这种机制成为"内容观察者"--contentObse ...

  6. Android灯光系统_编写HAL_lights.c【转】

    本文转载自:https://blog.csdn.net/qq_33443989/article/details/77074411 1>. 编写灯光系统的HAL层 之 HAL_light.c1&l ...

  7. 8.1 Android灯光系统_总体框架

    1.框架 APP(java语言实现) ------------------------------- JNI(c++语言实现)     向上提供Java执行c函数的接口  向下访问HAL ------ ...

  8. android: 使用通知

    8.1   使用通知 通知(Notification)是 Android 系统中比较有特色的一个功能,当某个应用程序希望向 用户发出一些提示信息,而该应用程序又不在前台运行时,就可以借助通知来实现.发 ...

  9. Android消息通知(notification)和PendingIntent传值

    通知栏的自定义布局:转:http://blog.csdn.net/vipzjyno1/article/details/25248021 拓展 实现自定义的通知栏效果: 这里要用到RemoteViews ...

随机推荐

  1. 运行Chromium浏览器无法登录谷歌账号因为缺少google api密钥

    管理员身份运行CMD,然后依次输入以下三行内容(因为比较长,最好拷贝,因为某原因粘贴第一行后,我输入了下,结果第一次没成功,可能是输入错误了.): setx GOOGLE_API_KEY " ...

  2. Balls and Boxes---hdu5810(推公式)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5810 有n个球m个盒子,随机把球放到盒子中,求每个盒子球个数的方差的期望值 E[V]; 推公式吧,或者 ...

  3. KVM--安装及初步使用

    KVM是Kernel-based Virtual Machine的简称,是一个开源的虚拟化模块,今天我将在CentOS7的操作系统上安装KVM,以下是我的安装步骤. 一.环境信息 系统: CentOS ...

  4. hammerjs wabapp h5 触屏手势一网打尽

    hammerjs官网    http://hammerjs.github.io/ 学习文章1 http://www.cnblogs.com/vajoy/p/4011723.html 学习文章2 htt ...

  5. UIPageViewController基本使用

    UIPageViewController基本使用 @interface ViewController ()<UIPageViewControllerDelegate,UIPageViewCont ...

  6. Spark Sort-Based Shuffle具体实现内幕和源码详解

    为什么讲解Sorted-Based shuffle?2方面的原因:一,可能有些朋友看到Sorted-Based Shuffle的时候,会有一个误解,认为Spark基于Sorted-Based Shuf ...

  7. [LeetCode] 561. Array Partition I_Easy tag: Sort

    Given an array of 2n integers, your task is to group these integers into n pairs of integer, say (a1 ...

  8. postman返回参数的截取

    同事在使用postman接口测试的时候,遇到这么一个问题,在一个参数里面,返回了一个类似数组的参数,如下: 然后现在需要把数组里面的两个参数分别保存到环境变量里面: 个人的想法是通过截取的方式进行数组 ...

  9. python 不同集合上元素的迭代 chain()

    itertools.chain()可以接受一个可迭代对象列表作为输入,并返回一个迭代器,有效的屏蔽掉在多个容器中迭代细节 >>> from itertools import chai ...

  10. 查看firefox浏览器 驱动geckodriver.exe文件的版本号的方法,以及下载链接

    1-进入到geckodriver.exe文件的目录: 2-在路径栏下输入cmd: 3-命令行界面下输入:geckodriver.exe -h 可以看到文件的帮助信息,其中第一行就列出了版本号 为0.1 ...