vivos saturacion samsung prime pantalla naturales más mas funciona colores color celular cambiar brillo baja aumentar android screen brightness screen-brightness

android - saturacion - Cambiar el brillo de la pantalla programáticamente(como con el widget de potencia)



j7 prime no baja el brillo (5)

EJEMPLO COMPLEJO:

try { //sets manual mode and brightnes 255 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) Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); //this will set the brightness to maximum (255) //refreshes the screen int br = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness = (float) br / 255; getWindow().setAttributes(lp); } catch (Exception e) {}

Estaba buscando cómo cambiar el brillo de la pantalla mediante programación y encontré que this es una solución muy buena y funciona bien, pero funciona solo mientras mi aplicación está activa. Después de que mi aplicación se apaga, el brillo vuelve al mismo valor que antes de iniciar mi aplicación.

Quiero poder cambiar el brillo al igual que cuando presiono el botón de brillo desde mi widget de potencia. En el widget de potencia que viene de Android hay 3 estados. Uno muy brillante uno muy oscuro y uno en el medio. ¿Es posible cambiar el brillo al igual que cuando alguien presiona en este widget?

Edit1: Creé esto y agregué permiso a mi manifiesto, pero cuando la aplicación se inició, no veo ningún cambio en el brillo. Intenté con 10 con 100 y ahora con 200 pero sin cambios. ¿Alguna sugerencia?

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); android.provider.Settings.System.putInt(this.getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, 200); }


Este es el código completo que encontré en funcionamiento:

Settings.System.putInt(this.getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 20); WindowManager.LayoutParams lp = getWindow().getAttributes(); lp.screenBrightness =0.2f;// 100 / 100.0f; getWindow().setAttributes(lp); startActivity(new Intent(this,RefreshScreen.class));

El código de mi pregunta no funciona porque la pantalla no se actualiza. Entonces, un truco para refrescar la pantalla es iniciar la actividad ficticia y luego crear una actividad ficticia para llamar a finish() para que los cambios de brillo entren en vigor.


He resuelto este problema hoy.

Como el primero, debes poner un permiso en tu archivo AndroidManifest.xml:

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

¿Dónde está el lugar exacto para ponerlo en el archivo?

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

Este permiso dice que puede cambiar la configuración que afecta a otras aplicaciones también.

Ahora puede activar y desactivar el modo automático de brillo

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)

¿El modo automático está encendido o apagado en este momento? Puedes obtener la información

int mode = -1; try { mode = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE); //this will return integer (0 or 1) } catch (Exception e) {}

Por lo tanto, si desea cambiar el brillo manualmente, se supone que primero debe establecer el modo manual y luego puede cambiar el brillo.

nota: SCREEN_BRIGHTNESS_MODE_AUTOMATIC es 1

nota: SCREEN_BRIGHTNESS_MODE_MANUAL es 0

Deberías usar esto

if (mode == Settings.System.SCREEN_BRIGHTNESS_MODE_AUTOMATIC) { //Automatic mode } else { //Manual mode }

en lugar de esto

if (mode == 1) { //Automatic mode } else { //Manual mode }

Ahora puedes cambiar el brillo manualmente

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, brightness); //brightness is an integer variable (0-255), but dont use 0

y lee el brillo

try { int brightness = Settings.System.getInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS); //returns integer value 0-255 } catch (Exception e) {}

Ahora todo está configurado correctamente, pero ... aún no puedes ver el cambio. ¡Necesitas una cosa más para ver el cambio! Actualiza la pantalla ... haz esto:

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) {}

No olvides el permiso ...

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


Pasar el contexto de la actividad mientras configuraba los parámetros también haría el trabajo sin necesidad de comenzar otra actividad. Lo siguiente funcionó para mí:

WindowManager.LayoutParams lp = this.getWindow().getAttributes(); lp.screenBrightness =0.00001f;// i needed to dim the display this.getWindow().setAttributes(lp);

Tenía este código en el método OnSensorChanged () que oscurecía la pantalla cada vez que se activaba.


Use la solución de Tor-Morten en ese enlace, pero también configure la configuración del brillo del sistema de la siguiente manera:

android.provider.Settings.System.putInt(getContext().getContentResolver(), android.provider.Settings.System.SCREEN_BRIGHTNESS, bright);

Donde bright es un número entero que va de 1 a 255.