0
工作以及在仿真器,但不這是我設置報警代碼:AlarmManager在真實設備
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
還是其他? 我已經努力嘗試,但未能找到任何解決方案。
你確定''setAlarm()'方法中變量'time'的值是否正確?添加一些調試日誌記錄並檢查您的logcat,以確保該警報實際上是在您認爲應該設置的時間內設置的。 – 2013-03-04 09:12:54
@DavidWasser:'時間'是正確的,因爲我同時在模擬器和真實設備中設置了警報。該警報應在4小時後觸發。在模擬器中觸發,但不是在真實的設備中。如果我將鬧鐘設置爲小於4小時,則在真實設備鬧鐘中工作良好。我認爲我的鬧鐘無法將我的設備從睡眠中喚醒。 – Shoshi 2013-03-04 09:54:10
我也試過'PowerManager.PARTIAL_WAKE_LOCK'而不是'PowerManager.FULL_WAKE_LOCK',但它不起作用 – Shoshi 2013-03-04 09:55:59