jos*_*eph 5 java android led flashlight
我试图在用户按下某个按钮时在前面的 LED 上实现 1 秒红色闪烁。但我很难找到有关如何访问和使用前置 LED 的文档、教程甚至代码示例(我的意思是位于“自拍”相机和触摸屏附近的 LED)。
我已经看到了使用手电筒和相机类(已弃用)的示例,但我相信这不是我想要的。
小智 3
无法直接访问前面的 LED 您可以使用 LED 的自定义颜色来安排通知
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();
Run Code Online (Sandbox Code Playgroud)
以 LED 的红色闪光为例:
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 );
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6382 次 |
| 最近记录: |