手机闪光

 

Notification也包含属性来设置手机LED的颜色和闪烁频率。

 

ledARGB属性用于设置LED的颜色,而ledOffMSledOnMS属性用来设置LED闪烁的频率和样式。你可以设置ledOnMS属性为1ledOffMS属性为0来让LED始终亮着;或者将两者设置为0来将LED关闭。一旦你设置了LED的设定,你也必须为Notificationflags属性添加FLAG_SHOW_LIGHTS标志位。

 

接下来的代码片段显示了如何将点亮红色的LED

 

notification.ledARGB = Color.RED;

notification.ledOffMS = 0;

notification.ledOnMS = 1;

notification.flags = notification.flags | Notification.FLAG_SHOW_LIGHTS;

 

控制颜色和闪烁频率是为向用户传递信息的另一种途径。

 

在地震监视的例子中,使用设备的LED来辅助传达级别,帮助用户从颜色上来感受地震的级别。在下面的片段中,LED的颜色取决于地震的级别,而闪烁的频率相反地关联于地震的影响:

 

int color;

if (quake.getMagnitude() < 5.4)

color = Color.GREEN;

else if (quake.getMagnitude() < 6)

color = Color.YELLOW;

else

color = Color.RED;

 

newEarthquakeNotification.ledARGB = color;

newEarthquakeNotification.ledOffMS = (int)vibrateLength;

newEarthquakeNotification.ledOnMS = (int)vibrateLength;

newEarthquakeNotification.flags = newEarthquakeNotification.flags | Notification.FLAG_SHOW_LIGHTS;

 

目前的Android模拟器不能直观地观察LED。这使得证实LED是否闪烁正确变得相当困难。对于硬件来说,每个设备可能设置有不同的LED颜色数量的限制。对于这些情况,只能尽可能近似的测试。

posted on 2009-09-08 22:36  xirihanlin  阅读(1086)  评论(0编辑  收藏  举报