当屏幕在Android v4上锁定时,AlarmManager不工作

当屏幕在Android v4上锁定时,AlarmManager不工作,android,alarmmanager,screen-lock,Android,Alarmmanager,Screen Lock,屏幕锁定时,我无法让AlarmManager工作。该应用程序在我的Sony Ericsson Xperia Active with Android 2.3.4上运行良好,无论屏幕是否锁定。我总是在LogCat中看到调试消息onReceive()。但当我尝试在Android版本更新的设备上运行该应用程序时,例如Android 4.1.2的三星Galaxy Xcover2,该应用程序只在屏幕打开时才工作。只有在屏幕打开时,我才会在LogCat for onReceive()中看到调试消息。当屏幕被锁

屏幕锁定时,我无法让AlarmManager工作。该应用程序在我的Sony Ericsson Xperia Active with Android 2.3.4上运行良好,无论屏幕是否锁定。我总是在LogCat中看到调试消息onReceive()。但当我尝试在Android版本更新的设备上运行该应用程序时,例如Android 4.1.2的三星Galaxy Xcover2,该应用程序只在屏幕打开时才工作。只有在屏幕打开时,我才会在LogCat for onReceive()中看到调试消息。当屏幕被锁定且应用程序停止工作时,我看不到调试消息。我试过其他有同样问题的设备。共同点似乎是(?)安卓版本

显示

....

<service
android:name=".MyGPSService"
android:enabled="true"
android:exported="false" >
</service>

<receiver android:name=".MyAMReceiver" />

</application>

</manifest>
接收级

....

public class MyAMReceiver extends BroadcastReceiver {
public MyAMReceiver() {
}


@Override
public void onReceive(Context context, Intent intent) {

//DEBUG!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Log.d("MyAMReceiver", "onReceive()");

// Wake CPU from sleep if unit screen is locked
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "My Tag");
wl.acquire();

// Start service
Intent intentS = new Intent(context, MyGPSService.class);
context.startService(intentS);

}
}

阅读上述内容后,将我的代码更改为:

alarmmanager.setRepeating(AlarmManager.ELAPSE_REALTIME_WAKEUP,SystemClock.elapsedRealtime()+10000,60000, pendingintent);
三星安卓4.1仍然拒绝在睡觉时启动AlarmManager(?)。不过仍然可以在索尼安卓2.3上使用

但根据SystemClock上的Android文档,这不会有任何区别: AlarmManager可以触发一次性或重复发生的事件,即使在设备处于深度睡眠状态或应用程序未运行时也会发生。事件可以通过您选择的currentTimeMillis()(RTC)或elapsedRealtime()(elapsedRealtime)进行计划,并在事件发生时引发意图广播


我以为我在这里找到了解决方案,但没有。三星4.1仍然拒绝启动AlarmManager(?)。也许不是我愚蠢,而是三星的人?我的Xcover2可能也有同样的问题吗?
alarmmanager.setRepeating(AlarmManager.ELAPSE_REALTIME_WAKEUP,SystemClock.elapsedRealtime()+10000,60000, pendingintent);