简体   繁体   中英

How to on/off LED in android not flash light?

I am trying to on/off LED on button click. But according to this , it works with notification. I have tried and it is working with notification. I want to on/off LED without notification. So far what I have tried is below:

Intent intent = new Intent(this, MainActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

    // Build notification
    // Actions are just fake
    Notification noti = new Notification.Builder(this)
            .setContentTitle("New mail from " + "test@gmail.com")
            .setContentText("Subject").setSmallIcon(R.mipmap.ic_launcher)
            .setContentIntent(pIntent).build();
    NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    // hide the notification after its selected
    noti.flags |= Notification.FLAG_AUTO_CANCEL|Notification.FLAG_SHOW_LIGHTS;
    noti.ledARGB = Color.RED;

    noti.ledOnMS = 100;
    noti.ledOffMS = 100;
    notificationManager.notify(0, noti);

It is working when screen is off and I have run application. Can someone help me doing this? Thanks.

I have not seen any APIs for dealing with the LEDs other than the Notification class, because it's inbuilt and those are totally handled by hardware based so only Notification class can handle it.So please don't waste your time to searching about it.

Hope you understand it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM