Tuesday, April 9, 2013

led light notification

download:  http://www.mediafire.com/?4bg5mk4od4c7rg6


package com.example.ledlight;

import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.graphics.Color;
import android.os.Bundle;
import android.os.Handler;

public class MainActivity extends Activity
{

int NOTIFICATION_ID = 1;
int LED_ON_MS = 100;
int LED_OFF_MS = 100;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

redFlashLight();

}

void redFlashLight() {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Notification notif = new Notification();
notif.ledARGB = Color.BLUE;
notif.flags = Notification.FLAG_SHOW_LIGHTS;
notif.ledOnMS = LED_ON_MS;
notif.ledOffMS = LED_OFF_MS;
nm.notify(NOTIFICATION_ID, notif);

// Program the end of the light :
Handler mCleanLedHandler = new Handler();

mCleanLedHandler.postDelayed(new Runnable() {

@Override
public void run() {
// TODO Auto-generated method stub

}
}, 500);
}

void clearLED() {
NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
nm.cancel(NOTIFICATION_ID);
}

@Override
protected void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();

clearLED();
}

}

No comments:

Post a Comment