【发布时间】:2018-02-12 12:15:44
【问题描述】:
每当用户按下某个按钮时,我都会尝试在前面的 LED 上实现 1 秒的红色闪烁。但是我很难找到有关如何访问和使用前置 LED 的文档、教程甚至代码示例(我指的是位于“自拍”相机和触摸屏附近的 LED)。
我已经看到了使用 flashlight 和 Camera 类(已弃用)的示例,但我相信这不是我想要的。
【问题讨论】:
标签: java android led flashlight
每当用户按下某个按钮时,我都会尝试在前面的 LED 上实现 1 秒的红色闪烁。但是我很难找到有关如何访问和使用前置 LED 的文档、教程甚至代码示例(我指的是位于“自拍”相机和触摸屏附近的 LED)。
我已经看到了使用 flashlight 和 Camera 类(已弃用)的示例,但我相信这不是我想要的。
【问题讨论】:
标签: java android led flashlight
没有直接进入前面的 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
【讨论】: