如何在Android平板电脑中启用LED闪烁?

时间:2012-09-11 13:05:09

标签: android

当用户点击平板电脑中的按钮时,我需要启用LED闪烁。这里我用下面的代码创建了一个示例应用程序此代码在Mobile(HTC Sensation)中运行良好。当我使用相同的平板电脑代码时,它将无法正常工作。为什么会发生这种情况,Log Cat中没有错误消息。我使用了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_ 闪烁 .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>

1 个答案:

答案 0 :(得分:2)

许多Android平板电脑没有通知LED。基于this product specificatio n,似乎这款平板电脑也没有。如果设备没有LED,则无法对LED进行闪烁。