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. Winform Splash Screen - VB.NET - Timer
- 7. VIM Colorschemes in Screen & PuTTy?
- 8. Screen Scraping HTML with C#
- 9. Shazam App like loading screen
- 10. OnResume Camera Reinit Black Screen
- 11. Hows Mozenda Screen Scraper codificado?
- 12. google.load causa vacío dom/screen
- 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. JBoss Session Timeout
- 17. Silverlight ClientHttp WebRequest timeout
- 18. Phonegap Geolocation Error: timeout
- 19. NGINX SSL Timeout
- 20. BroadcastReceiver onReceive timeout
- 21. Silverlight Async Timeout Error
- 22. Mysql phpMyadmin Timeout Pregunta
- 23. Implementa C# Generic Timeout
- 24. ASP.NET Session Timeout Testing
- 25. PHP max_execution_time no timeout
- 26. clojure (with-timeout ... macro)
- 27. GoogleAppEngine urlfetch timeout exception
- 28. ADO.Net DataReader timeout issue
- 29. Capistrano Deploy Timeout
- 30. Catch socket timeout excepción
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