Sé que es posible usar un wakelock para mantener la pantalla, la CPU, etc. pero ¿cómo puedo cambiar programáticamente la configuración "Screen Timeout" en un teléfono Android.Android Screen Timeout
9
A
Respuesta
11
El proveedor Settings.System ofrece una configuración de SCREEN_OFF_TIMEOUT que podría ser lo que está buscando.
27
public class HelloWorld extends Activity
{
private static final int DELAY = 3000;
int defTimeOut = 0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
// Be sure to call the super class.
super.onCreate(savedInstanceState);
// See assets/res/any/layout/hello_world.xml for this
// view layout definition, which is being set here as
// the content of our screen.
setContentView(R.layout.hello_world);
defTimeOut = Settings.System.getInt(getContentResolver(),
Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
}
@Override
protected void onDestroy()
{
super.onDestroy();
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, defTimeOut);
}
}
Y también no se olvide de agregar este permiso en el manifiesto:
android:name="android.permission.WRITE_SETTINGS"
13
anterior es correcta:
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
sino que también incluyen el permiso en el manifiesto:
android:name="android.permission.WRITE_SETTINGS"
1
Aquí hay una hoja de códigos, puedes hacer mo re.
long stand = Settings.System.getLong(
mContext.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT,
-1);
long sec = stand/1000;
String time = null;
if(stand<0) {
//close.
}
else if(sec >= 60) {//to minute
time = String.format(mContext.getString(R.string.minutes), (sec/60) + "");
} else {
time = String.format(mContext.getString(R.string.seconds),sec + "");
}
Cuestiones relacionadas
- 1. Android WebView TimeOut
- 2. Android App y Pattern Lock Screen
- 3. Android Emulator Freezing on Load Screen
- 4. 'rescatar en rbuf_fill': Timeout :: Error (Timeout :: Error)
- 5. Live Wallpaper Screen Rotation
- 6. VIM Colorschemes in Screen & PuTTy?
- 7. Screen Scraping HTML with C#
- 8. Hows Mozenda Screen Scraper codificado?
- 9. OnResume Camera Reinit Black Screen
- 10. Shazam App like loading screen
- 11. google.load causa vacío dom/screen
- 12. Winform Splash Screen - VB.NET - Timer
- 13. Android Phonegap - TIMEOUT ERROR al intentar establecer un WebViewClient
- 14. ¿Cuál es la diferencia entre Thread.Sleep (timeout) y ManualResetEvent.Wait (timeout)?
- 15. diferencia entre WebDriver Wait timeout y implicitlyWait timeout?
- 16. IMAP Idle Timeout
- 17. Catch socket timeout excepción
- 18. unicorn timeout handling
- 19. maneja lwp timeout efectivamente
- 20. Capistrano Deploy Timeout
- 21. Java InetAddress.isReachable() timeout
- 22. shell_exec() timeout management & exec()
- 23. Implementa C# Generic Timeout
- 24. ADO.Net DataReader timeout issue
- 25. JBoss Session Timeout
- 26. Apache HttpComponents HttpClient timeout
- 27. Silverlight Async Timeout Error
- 28. GoogleAppEngine urlfetch timeout exception
- 29. http connection timeout issues
- 30. BroadcastReceiver onReceive timeout
Gracias de nuevo Mark! – Tom
pero eso es una constante ¿no? – usman
@usman: No, los usuarios pueden cambiarlo a través de Configuración. – CommonsWare