2012-09-11 25 views
2

當使用單擊平板電腦上的按鈕時,我需要啓用LED閃爍。在這裏我使用下面的代碼創建了一個示例應用此代碼在Mobile(HTC Sensation)中正常工作。當我爲平板電腦使用相同的代碼時,它將無法工作。爲什麼會發生這種情況,Log Cat中沒有錯誤消息。我用Toshiba Thrive AT100 tablet如何在Android平板電腦中啓用LED閃爍?

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> 

回答

2

許多Android平板電腦沒有通知的LED。根據this product specificatio n看來,這款平板電腦也沒有。如果設備沒有LED,則無法閃爍LED。

+0

感謝您的快速響應,在這款平板電腦上有3個LED。一個用於指示電源(開啓),第二個用於電池充電,第三個用於顯示網絡信號。如果有任何可能使用這些用於我的使用? – Aerrow

+1

我不這麼認爲。如果ROM沒有設置爲使用其中的一種作爲通知燈,那麼實際上並沒有什麼可以做的。 –