So che è possibile utilizzare un wakelock per mantenere lo schermo, la CPU, ecc., Ma come posso modificare a livello di programmazione l'impostazione "Timeout schermo" su un telefono Android.Timeout schermo Android
9
A
risposta
11
Il provider Settings.System offre un'impostazione SCREEN_OFF_TIMEOUT che potrebbe essere quello che stai cercando.
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);
}
}
E anche non dimenticare di aggiungere questa autorizzazione a manifestare:
android:name="android.permission.WRITE_SETTINGS"
13
Sopra è corretto:
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
ma includono anche l'autorizzazione a manifestare:
android:name="android.permission.WRITE_SETTINGS"
1
Ecco un foglio di codice, puoi farlo mo ri.
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 + "");
}
Grazie ancora Marco! – Tom
ma questo è un diritto costante? – usman
@usman: No, gli utenti possono cambiarlo tramite Impostazioni. – CommonsWare