这是我设置闹钟的代码:
public void SetAlarm(Context context, int tag, long time){
AlarmManager am=(AlarmManager)context.getSystemService(Context.ALARM_SERVICE);
Intent i = new Intent(context, Alarm.class);
i.putExtra("position", tag);
PendingIntent pi = PendingIntent.getBroadcast(context, tag, i, PendingIntent.FLAG_CANCEL_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+ time, pi); // Millisec * Second * Minute
}
这是我的 onRecieve 方法:
public void onReceive(final Context context, Intent intent){
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK, "my wak up lo");
wl.acquire();
position = intent.getIntExtra("position", -1);
new PostManager(context, position);
wl.release();
}
这与模拟器配合得很好。同时我设置了一个警报,该警报将在 24 小时后在模拟器和真实设备中触发。这项工作由模拟器很好地完成,但不是在真实设备中。这是发生的事情PowerManager.FULL_WAKE_LOCK
还是其他什么?我已经努力但未能找到任何解决方案。