2012-05-12 122 views
0

我試圖創建一個應用程序總是活動的(即永遠不會在後臺),與按鈕時,按下可降低屏幕亮度。我聲明我不是Android編程的專家。按鈕來管理屏幕的亮度

回答

1

您可以設置屏幕亮度o按鈕點擊爲:

第一種方式:

@Override 
    public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    int curBrightnessValue=android.provider.Settings.System.getInt(
     getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS); 
    setBrightness(curBrightnessValue-25);//set BRIGHTNESS 
    } 
private void setBrightness(int brightness) { 
    try { 
     IHardwareService hardware = IHardwareService.Stub.asInterface( 
     ServiceManager.getService("hardware")); 
     if (hardware != null) { 
     hardware.setScreenBacklight(brightness); 
     } 
    } catch (RemoteException doe) {    
    } 

的Manifest.xml

<uses-permission android:name="android.permission.HARDWARE_TEST"></uses-permission> 

方式二:

@Override 
    public void onClick(View arg0) { 
    // TODO Auto-generated method stub 
    int curBrightnessValue=android.provider.Settings.System.getInt(
    getContentResolver(),android.provider.Settings.System.SCREEN_BRIGHTNESS); 
    int SysBackLightValue = curBrightnessValue-25; 
    android.provider.Settings.System.putInt(getContentResolver(), 
    android.provider.Settings.System.SCREEN_BRIGHTNESS, 
    SysBackLightValue); 
    } 

的AndroidManifest.xml:

<uses-permission android:name="android.permission.WRITE_SETTINGS"/> 

終於爲其他的方法來設置亮度看到this

+0

然而,這些代碼給錯誤 – bisssi