[英]WakeLock-related Mandelbug: does WakeLock.acquire() always succeed?
[英]WakeLock.acquire() does not work
我遇到了唤醒锁问题。 在一个类中,该类扩展了onCreate()中的Application类,我设置了AlarmManager
AlarmManager _alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
_wakeLockIntent = new Intent(getApplicationContext(), RepeatingWakelock.class);
_wakeLockIntent.setAction(WAKE_LOCK_ACTION);
_pIntent = PendingIntent.getBroadcast(getApplicationContext(), 26, _wakeLockIntent, 0);
_alarm.setRepeating(AlarmManager.RTC_WAKEUP, DateUtil.now().getTime(), 60000, _pIntent);
然后,我在BroadcastRecevier中尝试获取唤醒锁,但是它不起作用。
public static class RepeatingWakelock extends BroadcastReceiver{
private PowerManager _pm;
private PowerManager.WakeLock _wl;
public RepeatingWakelock() {
super();
}
@Override
public void onReceive(Context context, Intent intent) {
if (WAKE_LOCK_ACTION.equals(intent.getAction())){
_pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
_wl = _pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, "GPS WAKELOCK, ZOMBIES NEVER DIE!");
if (!_wl.isHeld()){
_wl.acquire();
}
}
}
}
屏幕只是无法打开。 我对此进行了调试,可以肯定地说是调用了_wl.acquire()行,但没有任何反应。 我在清单文件中具有WAKE_LOCK权限,也已在其中正确注册了广播接收器
他们来了
<receiver android:name="ru.cdc.android.test.app.Test$RepeatingWakelock">
<intent-filter>
<action android:name="wakelock"></action>
</intent-filter>
</receiver>
<uses-permission android:name="android.permission.WAKE_LOCK"></uses-permission>
任何帮助深表感谢!
解决方案非常简单,只需2x2。 我只需要添加
_wl = _pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP, "GPS WAKELOCK, ZOMBIES NEVER DIE!");`
“ PowerManager.ACQUIRE_CAUSES_WAKEUP”行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.