需要启动seriver时获取电源锁,退出时释放。
代码如下:
//申请设备电源锁
private void acquireWakeLock()
{
if (null == mWakeLock)
{
PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"");
if (null != mWakeLock)
{
mWakeLock.acquire();
}
}
}
//释放设备电源锁
private void releaseWakeLock()
{
if (null != mWakeLock)
{
mWakeLock.release();
mWakeLock = null;
}
}
代码如下:
//申请设备电源锁
private void acquireWakeLock()
{
if (null == mWakeLock)
{
PowerManager pm = (PowerManager)this.getSystemService(Context.POWER_SERVICE);
mWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK|PowerManager.ON_AFTER_RELEASE,"");
if (null != mWakeLock)
{
mWakeLock.acquire();
}
}
}
//释放设备电源锁
private void releaseWakeLock()
{
if (null != mWakeLock)
{
mWakeLock.release();
mWakeLock = null;
}
}