Controling Android's front led light

牧云@^-^@ 提交于 2019-12-05 14:45:01

There is no direct access to the front L.E.D. You can schedule Notifications with custom colours for the 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();

For Example For Red Flash of 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 );
}

The font light is called the Android Notification LED, which not all phones have, and the only way to control it is through launching a notification. There are some tutorials online showing how to do this such as: http://androidblogger.blogspot.co.uk/2009/09/tutorial-how-to-use-led-with-android.html

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!