сначала написать следующее разрешение в файле manifest.xml
<uses-permission android:name="android.permission.WRITE_SETTINGS" />
тогда, когда 10 секунд проход, запустите следующий код, чтобы уменьшить яркость устройства на его нижний уровень:
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0); //Set the system brightness
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress/(float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
и в случае, если вам нужно знать, как сделать уверен, что он ждал 10 секунд без каких-либо действий пользователя, реализовать приведенный выше код следующим образом:
public class YOUR_ACTIVITY extends Activity {
public static int x = 0; // must be static
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
run_thread();
}
private void run_thread(){
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
while(x < 10){
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
x++;
}
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 0); //Set the system brightness to it's lowest value
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress/(float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
}
});
thread.start();
}
@Override
public boolean onTouchEvent(MotionEvent event) {
x = 0;
Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 255); //Set the system brightness back to it's full value
android.view.WindowManager.LayoutParams w_lp = getWindow().getAttributes(); //Get the current window attributes
w_lp.screenBrightness = progress/(float)255; //Set the brightness of this window
getWindow().setAttributes(w_lp); //Apply attribute changes to this window
return true;
}
ХТ tp: //stackoverflow.com/a/7658364/346232 –