我正在尝试实现一个功能,每当用户按下某个按钮时,前置 LED 会闪烁一秒钟的红色。但我在寻找有关如何访问和操作前置 LED 的文档、教程或示例代码方面遇到了困难(我指的是靠近“自拍”摄像头和触摸屏的 LED)。
我已经看过使用手电筒和相机类(已弃用)的示例,但我认为那不是我要找的东西。
我已经看过使用手电筒和相机类(已弃用)的示例,但我认为那不是我要找的东西。
无法直接访问前端的 L.E.D. 您可以为 L.E.D. 定制颜色的通知计划。
Notification.Builder builder = new Notification.Builder(context);
builder.setContentIntent(pendingIntent)
.setSmallIcon(R.drawable.ic_launcher)
.setTicker("My Ticker")
.setWhen(System.currentTimeMillis())
.setAutoCancel(true)
.setDefaults(Notification.DEFAULT_VIBRATE | Notification.DEFAULT_SOUND | Notification.FLAG_SHOW_LIGHTS)
.setLights(0xff00ff00, 300, 100) // To change Light Colors
.setContentTitle("My Title 1")
.setContentText("My Text 1");
Notification notification = builder.getNotification();
例如对于 L.E.D 的红色闪光:
private void RedFlashLight()
{
NotificationManager nm = ( NotificationManager ) getSystemService(
NOTIFICATION_SERVICE );
Notification notif = new Notification();
notif.ledARGB = 0xFFff0000;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledOnMS = 100;
notif.ledOffMS = 100;
nm.notify(LED_NOTIFICATION_ID, notif);
// Program the end of the light :
mCleanLedHandler.postDelayed(mClearLED_Task, LED_TIME_ON );
}
字体亮度被称为Android通知LED,不是所有手机都有,并且唯一控制它的方法是通过启动通知。有一些在线教程展示了如何实现这一点,例如:http://androidblogger.blogspot.co.uk/2009/09/tutorial-how-to-use-led-with-android.html