2012-11-29 50 views
2

在我的應用程序中,我需要設置報警,並在狀態欄中顯示通知。 我將預定事件存儲在數據庫中,並在出現通知時移除事件。報警不會觸發設備轉動後的通知Android

當我關閉設備,並再次打開。 存在基本列表,但警報事件從不觸發。 當我關閉設備時,好像待處理事件被取消。

如何預防? 無論何時打開設備,我都需要顯示通知,並且出現鬧鐘的時間。

這是我如何設置報警:

Intent intent = new Intent(activity, TimeAlarm.class); 
    intent.putExtra(SHOW_NAME, showName); 
    intent.putExtra(SHOW_START_TIME, showStartTime); 
    intent.putExtra(CHANNEL_NAME, channelName); 
    intent.putExtra(VIBRATION_ENABLED, isVibrate); 
    intent.putExtra(SOUND_ENABLED, isSound); 

    int alarmId = (int) System.currentTimeMillis(); 

    intent.putExtra(ALARM_ID, alarmId); 

    PendingIntent pendingIntent = PendingIntent.getBroadcast(activity, 
      alarmId, intent, PendingIntent.FLAG_ONE_SHOT); 

    am.set(AlarmManager.RTC_WAKEUP, 
      System.currentTimeMillis() + delayMilis, pendingIntent); 

清單文件,我只有這個:

<receiver 
     android:name="com.moleandroid.tvprogramgui.alarm.TimeAlarm" 
/receiver> 

TimeAlarm類是我的接收器,並從那裏我顯示狀態欄通知。

任何想法最新怎麼了?

+0

設定標識爲PendingIntent.FLAG_UPDATE_CURRENT – Ramprasad

回答

1

這裏你需要做什麼來解決這個問題。通常當設備關閉時,它將取消所有報警的pendingIntent,因此當設備再次打開時它不會觸發。報警應用程序在內部執行什麼操作,而設備正在關閉/打開將啓動服務以註冊事件

請參閱此鏈接以在代碼中實現關閉和啓動意圖。因此,當設備通電安排對所有事件AlarmManager,我相信這會工作

Is there any way to receive a notification when the user powers off the device?

+0

使SENCE ...我會嘗試這種方式。我只需要啓動接收器。 – Veljko