2017-02-12 33 views
0

我正在開發一個應用程序,它允許用戶在android studio中的sqlite數據庫中存儲事件列表。我將這些日期,時間和這兩者都存儲在毫秒中,我想要做的是(如果可能)以我存儲的毫秒爲單位,並在事件即將發生前15分鐘設置提醒。我已經能夠設置每日重複通知(我預設了時間),並且不知道從哪裏開始實施每個事件的提醒。任何幫助將不勝感激。如何爲存儲在數據庫android studio中的事件設置提醒?

我讀過一篇文章做同樣的事情,但無法理解所寫的內容,也不確定答案是否解決了OP問題,因爲沒有評論可用。

How to set daily repeating notification in android studio at different times each day?

+0

由於您能夠創建重複通知,那麼您的問題是什麼?只需在AlarmManager中設置時間以在事件發生前15分鐘觸發,從事件中減去900000毫秒 – matip

+0

列表中有幾個事件,應該如何將提醒添加到所有事件? – Andrew

+0

將事件添加到數據庫時,您可以爲事件設置警報 – matip

回答

0

您應該使用AlarmManager和的PendingIntent;

AlarmManager manager = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE); 

     Intent intent = new Intent(this, YourReceiver.class); 


     PendingIntent pendingIntent = PendingIntent.getBroadcast(this, YOUR_REQUEST_CODE, intent, PendingIntent.FLAG_UPDATE_CURRENT); 

     manager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(), timeYouSavedinDB - 150000, pendingIntent); 
相關問題