5,597,501 Members 31,705 Now Online
XDA Developers Android and Mobile Development Forum

Multiple Led Notification Code

Tip us?
(Last edited by ownage16; 14th February 2014 at 10:30 AM.)
Junior Member - OP
Thanks Meter 0
Posts: 6
Join Date: Dec 2012
Default Multiple Led Notification Code


I would like to make an app that flashes the led from my phone (nexus 5) in different colors .

package com.example.led1;

//import java.util.Timer;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.NotificationCompat;
import android.view.Menu;
//import android.graphics.Color;

public class MainActivity extends Activity {

	protected void onCreate(Bundle savedInstanceState) {
	//	setContentView(R.layout.activity_main);
		Notification notf = new NotificationCompat.Builder(this)
	      .setLights(0xffff00, 1000, 100) 	     
	      .setLights(0xff0000, 5000, 100)
	      .setLights(0x0000FF, 10000, 100)
	NotificationManager mNotificationManager =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
	mNotificationManager.notify(2, notf);
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;


When i run this code only the last .setLights command works and thus only one color is used by the led. How can i make the led turn to all the three colors in the writen order ?
Masrepus's Avatar
Senior Member
Thanks Meter 54
Posts: 576
Join Date: Feb 2013
You will have to make three different light calls that have a pause in the middle. So to say you can do that by using delayed task for example.
But you will have to look tasks up in the android dev docs, cause i dont know how to implement that at the moment, sry

Phone : My new Nexus 4!
Pure KitKat 4.4.2 stock, no root, no mods (but only for the first time ;D)

Gesendet von Tapatalk

---------- Post added at 03:56 PM ---------- Previous post was at 03:55 PM ----------

Or do you want to make the led shine in three different colors at the same time??
Thats not possible, im afraid

Phone : My new Nexus 4!
Pure KitKat 4.4.2 stock, no root, no mods (but only for the first time ;D)

Gesendet von Tapatalk
sak-venom1997's Avatar
Senior Member
Thanks Meter 389
Posts: 897
Join Date: Feb 2013
Location: Lucknow

Ya as said above you need to make three different notifications and realy them at desired intervals you can use the Update notification fn. so you dont post a new notification each time
Try using TimerTasks / Handler

Sent from my GT-S5302 using Tapatalk 2
The Following User Says Thank You to sak-venom1997 For This Useful Post: [ Click to Expand ]
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes