我希望我的应用在后台运行,或者在手机进入睡眠状态后,当您接近某个纬度和经度时,我的应用会立即弹出到前台。无论是从睡眠还是其他应用程序都在前台,这都必须有效。 我正在使用服务和WakeLock。我很确定该服务正在运行,但我不知道如何检查,因为如果它不在foregrond中,调试器将不返回任何内容。如果它正常工作,那么我的WakeLock没有按预期工作。
public abstract class WakeLocker {
private static PowerManager.WakeLock fullWakeLock;
private static PowerManager.WakeLock partialWakeLock;
private static PowerManager pm;
public static void acquire(Context context) {
if (fullWakeLock != null) fullWakeLock.release();
if (partialWakeLock != null) partialWakeLock.release();
pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
fullWakeLock = pm.newWakeLock((PowerManager.SCREEN_BRIGHT_WAKE_LOCK |
PowerManager.FULL_WAKE_LOCK |
PowerManager.ACQUIRE_CAUSES_WAKEUP), "Loneworker - FULL WAKE LOCK");
partialWakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "Loneworker - PARTIAL WAKE LOCK");
partialWakeLock.acquire();
}
public static void release() {
if (fullWakeLock != null) {
fullWakeLock.release();
fullWakeLock = null;
}
if (partialWakeLock != null) {
partialWakeLock.release();
partialWakeLock = null;
}
}
public static void wakeDevice(Context context) {
fullWakeLock.acquire();
//KeyguardManager keyguardManager = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
//KeyguardManager.KeyguardLock keyguardLock = keyguardManager.newKeyguardLock("TAG");
//keyguardLock.disableKeyguard();
}
public static boolean fullWakeLockActive() {
return fullWakeLock != null;
}
}
这里正在获取fullWakeLock
if (makeUseOfNewLocation(location) < 20) {
if (WakeLocker.fullWakeLockActive())
WakeLocker.wakeDevice(allert.getMA());
if (callProgress.isOffHook()) {
new BlinkBack(allert.getMA());
}
答案 0 :(得分:0)
唤醒锁本身无法将设备从睡眠状态唤醒或导致设备出现在前台。您必须使用位置服务或警报唤醒设备,然后使用唤醒锁保持设备唤醒并将应用程序的UI组件触发到前台。