Ho risolto questo problema oggi.
Mentre il primo si deve mettere un permesso nel file AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
Dove si trova il luogo esatto per dirla nel file?
<manifest>
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application>
<activity />
</application>
</manifest>
Questa autorizzazione dice, che si è permesso di modificare le impostazioni che influiscono altre applicazioni.
Ora è possibile impostare la modalità automatica della luminosità e disattivare
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC); //this will set the automatic mode on
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL); //this will set the manual mode (set the automatic mode off)
è la modalità automatica attivata o disattivata in questo momento?È possibile ottenere le informazioni
int mode = -1;
try {
mode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE); //this will return integer (0 or 1)
} catch (Exception e) {}
Quindi, se si desidera modificare la luminosità manualmente, si suppone di impostare prima la modalità manuale e dopo che è possibile modificare la luminosità.
nota: SCREEN_BRIGHTNESS_MODE_AUTOMATIC è 1
nota: SCREEN_BRIGHTNESS_MODE_MANUAL è 0
si dovrebbe usare questa
if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) {
//Automatic mode
} else {
//Manual mode
}
invece di questo
if (mode == 1) {
//Automatic mode
} else {
//Manual mode
}
Ora è possibile modificare la luminosità manualmente
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness); //brightness is an integer variable (0-255), but dont use 0
e leggere la luminosità
try {
int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); //returns integer value 0-255
} catch (Exception e) {}
Ora tutto è impostato correttamente, ma ... non si può vedere il cambiamento ancora. Hai bisogno di un'altra cosa per vedere il cambiamento! Aggiornare la schermata ... quindi fare questo:
try {
int br = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); //this will get the information you have just set...
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness = (float) br/255; //...and put it here
getWindow().setAttributes(lp);
} catch (Exception e) {}
Non dimenticare il permesso ...
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
l'hai provato questi http://stackoverflow.com/questions/3865883/changing-screen-brightness-in-android-emulator non shore se il cambiamento di proprietà di luminosità personalizzata è – PedroAGSantos