控制Android LED灯颜色代码

来源:互联网 发布:软件体系结构图 编辑:程序博客网 时间:2024/05/01 13:14

很多Android手机上都配有LED灯,比如HTC的手机在充电、新来短信等时候都会有响应的指示,其实很简单的这都是NotificationManager的一些参数而已,下面Android123给大家说下如何通过代码控制LED灯的闪烁,因为有些机型没有LED灯或颜色种类较少,发布时需要真机观察。

        final int ID_LED=19871103;
        NotificationManager nm=(NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        Notification notification = new Notification();
        notification.ledARGB = 0xFFFFFF;  //这里是颜色,我们可以尝试改变,理论上0xFF0000是红色,0x00FF00是绿色
        notification.ledOnMS = 100;
        notification.ledOffMS = 100;
        notification.flags = Notification.FLAG_SHOW_LIGHTS;
        nm.notify(ID_LED, notification);
        nm.cancel(ID_LED);

 

 

 

转帖地址:http://www.android123.com.cn/androidkaifa/655.html