Light源码

public abstract class Light {    public static final int LIGHT_FLASH_NONE = 0;    public static final int LIGHT_FLASH_TIMED = 1;    public static final int LIGHT_FLASH_HARDWARE = 2;    /**     * Light brightness is managed by a user setting.     */    public static final int BRIGHTNESS_MODE_USER = 0;    /**     * Light brightness is managed by a light sensor.     */    public static final int BRIGHTNESS_MODE_SENSOR = 1;    public abstract void setBrightness(int brightness);    public abstract void setBrightness(int brightness, int brightnessMode);    public abstract void setColor(int color);    public abstract void setFlashing(int color, int mode, int onMS, int offMS);    public abstract void pulse();    public abstract void pulse(int color, int onMS);    public abstract void turnOff();}

public abstract class LightsManager {    public static final int LIGHT_ID_BACKLIGHT = 0;//背光灯    public static final int LIGHT_ID_KEYBOARD = 1;//键盘灯    public static final int LIGHT_ID_BUTTONS = 2;//Home Menu,Back键灯    public static final int LIGHT_ID_BATTERY = 3;  //充电灯    public static final int LIGHT_ID_NOTIFICATIONS = 4;//通知灯    public static final int LIGHT_ID_ATTENTION = 5;   //重要灯    public static final int LIGHT_ID_BLUETOOTH = 6;//蓝牙    public static final int LIGHT_ID_WIFI = 7;//WIFI灯    public static final int LIGHT_ID_COUNT = 8;    public abstract Light getLight(int id);}

系统开发点亮灯已充电灯为例

    <!-- Default color for notification LED. -->    <color name="config_defaultNotificationColor">#ffffffff</color>    <!-- Default LED on time for notification LED in milliseconds. -->    <integer name="config_defaultNotificationLedOn">500</integer>    <!-- Default LED off time for notification LED in milliseconds. -->    <integer name="config_defaultNotificationLedOff">2000</integer>    <!-- Default value for led color when battery is low on charge -->    <integer name="config_notificationsBatteryLowARGB">0xFFFF0000</integer>    <!-- Default value for led color when battery is medium charged -->    <integer name="config_notificationsBatteryMediumARGB">0xFFFFFF00</integer>    <!-- Default value for led color when battery is fully charged -->    <integer name="config_notificationsBatteryFullARGB">0xFF00FF00</integer>    <!-- Default value for LED on time when the battery is low on charge in miliseconds -->    <integer name="config_notificationsBatteryLedOn">125</integer>    <!-- Is the notification LED intrusive? Used to decide if there should be a disable option -->    <bool name="config_intrusiveNotificationLed">false</bool>    <!-- Default value for LED off time when the battery is low on charge in miliseconds -->    <integer name="config_notificationsBatteryLedOff">2875</integer>


    private final class Led {        private final Light mBatteryLight;        private final int mBatteryLowARGB;        private final int mBatteryMediumARGB;        private final int mBatteryFullARGB;        private final int mBatteryLedOn;        private final int mBatteryLedOff;        public Led(Context context, LightsManager lights) {            mBatteryLight = lights.getLight(LightsManager.LIGHT_ID_BATTERY);            mBatteryLowARGB = context.getResources().getInteger(                    com.android.internal.R.integer.config_notificationsBatteryLowARGB);//0xFFFF0000            mBatteryMediumARGB = context.getResources().getInteger(                    com.android.internal.R.integer.config_notificationsBatteryMediumARGB);//            mBatteryFullARGB = context.getResources().getInteger(                    com.android.internal.R.integer.config_notificationsBatteryFullARGB);            mBatteryLedOn = context.getResources().getInteger(                    com.android.internal.R.integer.config_notificationsBatteryLedOn);            mBatteryLedOff = context.getResources().getInteger(                    com.android.internal.R.integer.config_notificationsBatteryLedOff);        }        mBatteryLight.setFlashing(mBatteryLowARGB, Light.LIGHT_FLASH_TIMED,                            mBatteryLedOn, mBatteryLedOff);//红灯闪     mBatteryLight.setColor(mBatteryFullARGB);//绿灯亮  mBatteryLight.turnOff();//充电灯关闭


第三方应用点亮灯



//如果硬件支持通知灯 

findViewById(R.id.red_open).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {turnOnLED(Color.RED);}});findViewById(R.id.green_open).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {turnOnLED(Color.GREEN);}});findViewById(R.id.blue_open).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {turnOnLED(Color.BLUE);}});findViewById(R.id.blue_close).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {turnOnLED(Color.YELLOW);}});findViewById(R.id.green_close).setOnClickListener(new OnClickListener() {@Overridepublic void onClick(View v) {turnOffLED();}});} private void turnOnLED(int color){  System.out.println("wangruiCIT_LEDTEST START!!!");int ID_LED = 19871103; NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification();notification.ledARGB = color;  //notification.defaults |= Notification.DEFAULT_LIGHTS;    notification.ledOnMS = 1; notification.ledOffMS =0; //notification.ledOnMS = 125; //notification.ledOffMS =2875; notification.flags = Notification.FLAG_SHOW_LIGHTS; nm.notify(ID_LED, notification); }  private void turnOffLED(){  System.out.println("wangruiCIT_LEDTEST START!!!");int ID_LED = 19871103; NotificationManager nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification();notification.ledARGB = Color.BLACK;  //notification.defaults |= Notification.DEFAULT_LIGHTS;    notification.ledOnMS = 0; notification.ledOffMS = 0; notification.flags = Notification.FLAG_SHOW_LIGHTS; nm.notify(ID_LED, notification); }}



或者直接这样,前提是三方应用必须打入系统应用,并且在应用程序的AndroidManifest.xml中的manifest节点中加入android:sharedUserId="android.uid.system"这个属性。

通过系统一起编译

static String RED_LED_DEV = "/sys/class/leds/red/brightness";    static String GREEN_LED_DEV = "/sys/class/leds/green/brightness";    static String BLUE_LED_DEV = "/sys/class/leds/blue/brightness";    static void setLedStatus (String ledDev, boolean setStatusOn) {       try {           FileOutputStream fLed = new FileOutputStream(ledDev);           fLed.write((setStatusOn ? "255" : "0").getBytes());           fLed.close();       } catch (Exception e) {           e.printStackTrace();        }    }    










更多相关文章

  1. 【黑马Android】(13)Linux操作系统/cron计划任务
  2. [置顶] 基于android2.3.5系统:Android动态库链接
  3. Android启动后,加载的2类service (Native 系统Service, Java 系统
  4. [Android记录]Android(安卓)Studio问题记录
  5. Android系统架构和四大组件
  6. Android(安卓)App的运行环境及Android系统架构概览
  7. 第一篇 Android(安卓)驱动开发之简单概述
  8. android合理配置PRODUCT_LOCALES为你的系统瘦身减负
  9. android 开发-系统设置界面的实现

随机推荐

  1. 用Dbus与android的bluz通信
  2. 关于Android的问号?和@符号的用法
  3. Android之进度条控件和常用资源分类总结
  4. android 玩转ContentProvider之二--实现多
  5. android core dump测试
  6. android UI进阶之弹窗的使用
  7. Android系统的Binder机制分析
  8. android TextView设置字过多长长度后面显
  9. [Android] AIDL的使用情况和实例介绍
  10. Android中使用mvvm