保持屏幕常亮

在处于应用特定页面时,如何保持屏幕常亮,下面贴上这段代码:
public class WakeLockActivity extends Activity {

	PowerManager powerManager = null;
	WakeLock wakeLock = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.main);
		this.powerManager = (PowerManager) this
				.getSystemService(Context.POWER_SERVICE);
		this.wakeLock = this.powerManager.newWakeLock(
				PowerManager.FULL_WAKE_LOCK, "My Lock");
	}

	@Override
	protected void onResume() {
		super.onResume();
		this.wakeLock.acquire();
	}

	@Override
	protected void onPause() {
		super.onPause();
		this.wakeLock.release();
	}

}


当然不要忘了添加权限:
<uses-permission android:name="android.permission.WAKE_LOCK" />

你可能感兴趣的:(屏幕)