Android申请电源锁与释放电源锁

权限配置

1
<uses-permission android:name="android.permission.WAKE_LOCK"/>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
// 申请电源锁,禁止休眠
private WakeLock mWakeLock = null;

private void acquireWakeLock() {
if (null == mWakeLock) {
PowerManager pm = (PowerManager) getActivity().getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, this
.getClass().getCanonicalName());
if (null != mWakeLock) {
mWakeLock.acquire();
}
}
}

// 释放设备电源锁
private void releaseWakeLock() {
if (null != mWakeLock) {
mWakeLock.release();
mWakeLock = null;
}
}

Powered by AppBlog.CN     浙ICP备14037229号

Copyright © 2012 - 2020 APP开发技术博客 All Rights Reserved.

访客数 : | 访问量 :