Aerrow
Aerrow

Reputation: 12134

How can i enable LED Blinking in Android Tablets?

I need to enable LED blinking on when the use click the button in tablet. Here i created a sample application using below code. This code is working fine in Mobile (HTC Sensation). When i use the same code for Tablet, it won't work. Why this will happens, there is no error message in Log Cat. I used Toshiba Thrive AT100 tablet.

LED_Blinking_Activity.java

public class LED_Blinking_Activity extends Activity {

    Button on, off;
    int LED_NOTIFICATION_ID = 0;
    Context context;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_led__blinking_);
        on = (Button) findViewById(R.id.button1);
        off = (Button) findViewById(R.id.button2);
        final Vibrator vibe = (Vibrator) this
                .getSystemService(VIBRATOR_SERVICE);
        on.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
                Notification notif = new Notification();
                notif.ledARGB = 0xFFff0000; // Green color 0xFF00FF00
                notif.flags = Notification.FLAG_SHOW_LIGHTS;
                notif.ledOnMS = 100;
                notif.ledOffMS = 1000;
                nm.notify(LED_NOTIFICATION_ID, notif);

                vibe.vibrate(50); // 50 is time in ms

            }
        });

        off.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub
                ClearLED();
            }
        });
    }

    private void ClearLED() {
        NotificationManager nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
        nm.cancel(LED_NOTIFICATION_ID);
    }

    private Runnable mClearLED_Task = new Runnable() {
        public void run() {
            synchronized (LED_Blinking_Activity.this) {
                ClearLED();
            }
        }
    };
}

activity_led_blinking.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="45dp"
        android:text="Turn on LED" />

    <Button
        android:id="@+id/button2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/button1"
        android:layout_centerVertical="true"
        android:text="Turn o LED" />

</RelativeLayout>

Upvotes: 2

Views: 981

Answers (1)

Wesley Wiser
Wesley Wiser

Reputation: 9851

Many Android tablets do not have notification leds. Based on this product specification it appears that this tablet does not have one either. You can't flash the led if the device doesn't have one.

Upvotes: 2

Related Questions