led灯的控制在http://gqdy365.iteye.com/admin/blogs/2208344中写的方法是直接通过操作led设置来控制灯的开关。这样做的问题是未按Android标准结构实现,可能存在潜在的问题,后面分析的一下灯的源码,原来Android系统里面已经提供的相关的实现。
Android系统标准的led可以通过发送通知来控制led灯,做法如下:
private void notificactionLed() {
NotificationManager manager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification();
notification.icon = R.drawable.ic_launcher;
notification.tickerText = "发送灯通知";
/**
* To turn the LED off, pass 0 in the alpha channel for colorARGB or 0 for both ledOnMS and ledOffMS.
To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.
To flash the LED, pass the number of milliseconds that it should be on and off to ledOnMS and ledOffMS.
*/
notification.defaults = Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xffffffff;//控制led灯的颜色
//灯闪烁时需要设置下面两个变量
notification.ledOnMS = 300;
notification.ledOffMS = 300;
notification.flags = Notification.FLAG_SHOW_LIGHTS;
Intent intent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0,
intent, PendingIntent.FLAG_ONE_SHOT);
notification.setLatestEventInfo(this, "灯测试", "led灯测试", pendingIntent);
manager.notify(1, notification);
}
通过查看灯的实现源码,发现如下问题:
在来电或者系统屏幕亮的情况下是没办法控制灯的,具体源码(com.android.server.NotificationManagerService)中是这样的:
private void More ...updateLightsLocked()
2229 {
2230 // handle notification lights
2231 if (mLedNotification == null) {
2232 // get next notification, if any
2233 int n = mLights.size();
2234 if (n > 0) {
2235 mLedNotification = mLights.get(n-1);
2236 }
2237 }
2238
2239 // Don't flash while we are in a call or screen is on
2240 if (mLedNotification == null || mInCall || mScreenOn) {
2241 mNotificationLight.turnOff();
2242 } else {
2243 final Notification ledno = mLedNotification.sbn.getNotification();
2244 int ledARGB = ledno.ledARGB;
2245 int ledOnMS = ledno.ledOnMS;
2246 int ledOffMS = ledno.ledOffMS;
2247 if ((ledno.defaults & Notification.DEFAULT_LIGHTS) != 0) {
2248 ledARGB = mDefaultNotificationColor;
2249 ledOnMS = mDefaultNotificationLedOn;
2250 ledOffMS = mDefaultNotificationLedOff;
2251 }
2252 if (mNotificationPulseEnabled) {
2253 // pulse repeatedly
2254 mNotificationLight.setFlashing(ledARGB, LightsService.LIGHT_FLASH_TIMED,
2255 ledOnMS, ledOffMS);
2256 }
2257 }
2258 }
在com.android.server.LightsService中对灯的操作做了封装,所有灯的操作调用了:
116 private void More ...setLightLocked(int color, int mode, int onMS, int offMS, int brightnessMode) {
117 if (color != mColor || mode != mMode || onMS != mOnMS || offMS != mOffMS) {
118 if (DEBUG) Slog.v(TAG, "setLight #" + mId + ": color=#"
119 + Integer.toHexString(color));
120 mColor = color;
121 mMode = mode;
122 mOnMS = onMS;
123 mOffMS = offMS;
124 setLight_native(mNativePointer, mId, color, mode, onMS, offMS, brightnessMode);
125 }
126 }
其中setLight_native方法是一个本地方法,代码在 frameworks/base/services/jni/com_android_server_LightsService.cpp中。
在com_android_server_LightsService中最终还是通过操作设备文件来实现灯的开关,文件位置如下:
参考资料:
http://blog.csdn.net/u011630458/article/details/22280841
http://blog.csdn.net/u011630458/article/details/22312901
- 大小: 53.5 KB
分享到:
相关推荐
一、查看LED显示屏显示的颜色是否与播映源的颜色保持高度一致,及相邻模组之间是否存在较明显的色块色差。以此保证所装置的LED显示屏图画的真实感,控制系统、灰度等级、扫描频率的优良性。 二、查看显示屏上是否有...
Android内核led灯驱动程序,用于内核驱动程序开发实验,主要功能是实现led灯的点亮和熄灭
单片机 LED显示屏动态显示和远程监控的实现单片机 LED显示屏动态显示和远程监控的实现单片机 LED显示屏动态显示和远程监控的实现单片机 LED显示屏动态显示和远程监控的实现单片机 LED显示屏动态显示和远程监控的实现...
资源包中包含了源代码和指令格式说明,包括安卓端和arduino端代码,且有详细注释;...Android端程序功能和界面都很简单,提供界面连接蓝牙模块以及实现arduino端的LED灯亮度连续可调。方便初学者使用。
户外全彩LED显示屏生产安装流程。安装工程师必备的工具书
Github已开源:...详细内容也可看我的文章:https://mp.csdn.net/mp_blog/creation/editor/124478948《Android Studio设计APP实现与51单片机通过WIFI模块(ESP8266-01S)通讯控制LED灯亮灭的设计源码【详解】》
Android驱动例子(LED灯控制).pdf
第四章: LED显示屏的组成 …………………….. 第11页 详细介绍室内外LED显示屏的组成,结构,控制系统,配电系统, 典型系统的安装设置,软件使用方法等问题。 第五章: 显示屏相关计算方法 ……………………第33页 ...
户外LED显示屏立柱结构施工流程.docx
本文主要介绍了室外LED显示屏制作流程。
对于全彩LED显示屏,LED灯珠作为其最关键的部件,LED灯珠的品质对LED显示屏的品质起着很重要的决定作用。本文就为大家详解LED灯珠封装如何影响LED显示屏品质?
LED显示屏管理资料 LED显示屏管理资料 LED显示屏管理资料 LED显示屏管理资料
安卓智能家居,androidapp源码,初步是实现开关、led灯亮度,电机pwm等,定时
LED显示屏操作流程:1、 框架制作:材料有铝型材,拐角,角铁,螺丝。根据客户要求选择模组的规格......
android实现监控网络变化控制LED灯闪烁功能,需求有:1.不管是WiFi还是以太网都需要监听。 2.网络未连接时亮红灯,网络连接成功但是不能成功上网时绿灯闪烁。 3.网络连接成功且可以上网时绿灯亮。 4.待机时无论...
基于ARM744B0的LED显示屏控制系统设计与实现.pdf基于ARM744B0的LED显示屏控制系统设计与实现.pdf基于ARM744B0的LED显示屏控制系统设计与实现.pdf基于ARM744B0的LED显示屏控制系统设计与实现.pdf基于ARM744B0的LED...
LED显示屏主要组成部分有那些-LED显示屏安装流程.doc
LED显示屏在安装及使用过程中总会出现不同的信号,相当于LED显示屏特有的语言,LED显示屏的信号传输问题时有发生,这些信号的出现有什么意思?如果在一场重大开幕式上,LED显示屏突然因信号问题出现乱码,那造成的...
摘 要:由于普通LED点阵显示屏动态显示通常采用硬件扫描驱动,这在一些需要特殊显示的场合显得不够灵活。文中提出了一种利用PC机和单片机的通讯来实现显示屏灵活...基于单片机下LED显示屏动态显示和远程监控的实现.doc
LED显示屏 LED显示屏 LED显示屏 LED显示屏 LED显示屏 LED显示屏