java – 控制Android的前置灯
作者:互联网
当用户按下某个按钮时,我正试图在前面引导1秒的红色闪烁.但我很难找到关于如何访问和使用前置led的文档,教程甚至代码示例(我指的是位于“自拍”相机和触摸屏旁边的LED).
我已经看过使用手电筒和Camera类的例子(不推荐使用),但我相信这不是我想要的.
解决方法:
没有直接进入前面的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 );
}
标签:java,android,flashlight,led 来源: https://codeday.me/bug/20190607/1195205.html