强制操作锁屏开关有时候是必须的,但是请不要经常使用,因为它是耗电的。
设定权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
public class DoNotDimScreen extends Activity {
private PowerManager.WakeLock wl;
@Override
protected void onCreate(Bundle savedInstanceState) {
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
}
@Override
protected void onPause() {
super.onPause();
wl.release();
}
@Override
protected void onResume() {
super.onResume();
wl.acquire();
}
}