D.J
D.J

Reputation: 1559

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 " + "[email protected]")
            .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.

Upvotes: 0

Views: 74

Answers (1)

Jyubin Patel
Jyubin Patel

Reputation: 1373

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.

Upvotes: 1

Related Questions