Results 1 to 2 of 2
  1. #1
    gongshow20 is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default LED Notifications

    I was just messing around creating an app for fun, that I could possibly add on to later. I just started throwing together a simple activity with three buttons that when pressed would activate the led to a specific color. I'm having trouble getting the notifications to work. Here my main activity any one have any pointers for me?

    Java Code:
    import android.os.Bundle;
    import android.app.Activity;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.view.Menu;
    import android.view.View;
    import android.view.View.OnClickListener;
    import android.widget.Button;
    
    public class MainActivity extends Activity {
    
    	private Button redButton;
    	private Button blueButton;
    	private Button greenButton;
    
    	@Override
    	protected void onCreate(Bundle savedInstanceState) {
    		super.onCreate(savedInstanceState);
    		setContentView(R.layout.activity_main);
    
    		redButton = (Button) findViewById(R.id.red_button);
    		blueButton = (Button) findViewById(R.id.blue_button);
    		greenButton = (Button) findViewById(R.id.green_button);
    
    		redButton.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				redLight();
    			}
    		});
    		blueButton.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				blueLight();
    			}
    		});
    		greenButton.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				greenLight();
    			}
    		});
    
    	}
    
    	@Override
    	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;
    	}
    
    	private void blueLight() {
    
    		NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    		Notification notif = new Notification();
    		notif.defaults = 0;
    		notif.ledARGB = 0xFF00FFFF;
    		notif.flags = Notification.FLAG_SHOW_LIGHTS;
    		notif.ledOnMS = 100;
    		notif.ledOffMS = 100;
    		nm.notify(0, notif);
    
    	}
    
    	private void greenLight() {
    		Notification notif = new Notification();
    		notif.ledARGB = 0xFF00FFFF;
    		notif.flags = Notification.FLAG_SHOW_LIGHTS;
    		notif.ledOnMS = 100;
    		notif.ledOffMS = 100;
    	}
    
    	private void redLight() {
    		Notification notif = new Notification();
    		notif.ledARGB = 0xFF00FFFF;
    		notif.flags = Notification.FLAG_SHOW_LIGHTS;
    		notif.ledOnMS = 100;
    		notif.ledOffMS = 100;
    	}
    
    }
    Edit:
    Nothing was wrong with this code it the LED doesn't work when the screen is on. I want to create an app where the user can adjust the colors of led, vibrate, and other notifications. I made a small app practicing working with the LED's but I don't know how to change the built in Android preferences. Any ideas of how to do this, where I should look for help? I've been reading the documentation but I have not been able to find out how Android stores these preferences.

    The app I am looking to create would be similar to light flow - LED Controller app.
    Last edited by gongshow20; 05-20-2013 at 09:03 PM. Reason: Figured out problem.

  2. #2
    gongshow20 is offline Member
    Join Date
    May 2013
    Posts
    6
    Rep Power
    0

    Default Re: LED Notifications

    I was able to figure out that LED's will not show if the screen is on. I want to start adapting my program to change the led color for different notifications. What resources would I have to use to fix this? I'm assuming that my app would be able to change the users preferences to their own picking. How would I go about implementing this?

Similar Threads

  1. [Help] Not getting Email notifications
    By totalspelnerd in forum Suggestions & Feedback
    Replies: 1
    Last Post: 05-04-2013, 08:31 PM
  2. JConsole Notifications
    By eccadmin in forum New To Java
    Replies: 0
    Last Post: 01-25-2013, 10:28 PM
  3. SQL Server and Notifications
    By nicox1984 in forum New To Java
    Replies: 0
    Last Post: 03-07-2012, 03:36 PM
  4. Event handling vs Notifications
    By spentak in forum New To Java
    Replies: 1
    Last Post: 05-18-2011, 06:36 PM
  5. Notifications
    By semoche in forum Enterprise JavaBeans (EJB)
    Replies: 1
    Last Post: 01-09-2010, 07:23 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •