Je sais qu’il est possible d’utiliser un wakelock pour maintenir l’écran, l’unité centrale, etc., mais comment puis-je modifier par programmation le paramètre “Délai de l’écran” sur un téléphone Android.
Le fournisseur Settings.System propose un paramètre SCREEN_OFF_TIMEOUT qui pourrait correspondre à ce que vous recherchez.
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); } }
Et n’oubliez pas d’append cette permission dans manifest:
android:name="android.permission.WRITE_SETTINGS"
Ci-dessus est correct:
Settings.System.putInt(getContentResolver(),Settings.System.SCREEN_OFF_TIMEOUT, DELAY);
Mais incluez également la permission dans manifest:
android:name="android.permission.WRITE_SETTINGS"
Voici une feuille de code, vous pouvez faire plus.
long stand = Settings.System.getLong( mContext.getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, -1); long sec = stand / 1000; Ssortingng time = null; if(stand<0) { //close. } else if( sec >= 60) {//to minute time = Ssortingng.format(mContext.getSsortingng(R.ssortingng.minutes), (sec / 60) + ""); } else { time = Ssortingng.format( mContext.getSsortingng(R.ssortingng.seconds),sec + ""); }