- Adding code to the class files;
# 注意pManager和mWakeLock需要提前定义
@Override
protected void onResume() {
super.onResume();
pManager = ((PowerManager) getSystemService(POWER_SERVICE));
mWakeLock = pManager.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK
| PowerManager.ON_AFTER_RELEASE, TAG);
mWakeLock.acquire();
}
@Override
protected void onPause() {
super.onPause();
if(null != mWakeLock){
mWakeLock.release();
}
}
- After the declaration of competence, the code takes effect.
<uses-permission android:name="android.permission.WRITE_SETTINGS" />