Frage

I'm using the AlarmManager class to notify the user everyday in specific time (user will choose the time from time picker) every thing worked great al7mdllah ^^ But I want to get that time from the alarmManger and display it in the application to get a better UX is there any way to get the alarm time?

Here's my code

public void witer_reminder(View view)
{
    am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    Intent intent = new Intent(this, Witer_Notification.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0,
        intent, PendingIntent.FLAG_CANCEL_CURRENT);

    Calendar cal = Calendar.getInstance();
    Calendar calSet = (Calendar) cal.clone();

    calSet.set(Calendar.HOUR_OF_DAY, picker.getCurrentHour());
    calSet.set(Calendar.MINUTE,picker.getCurrentMinute());
    calSet.set(Calendar.SECOND, 0);
    calSet.set(Calendar.MILLISECOND, 0);

     if(calSet.compareTo(cal) <= 0){
            //Today Set time passed, count to tomorrow
            calSet.add(Calendar.DATE, 1);
           }

      am.setRepeating(AlarmManager.RTC_WAKEUP, calSet.getTimeInMillis(),
              24*60*60*1000, pendingIntent);



}
War es hilfreich?

Lösung

But I want to get that time from the alarmManger and display it in the application to get a better UX is there any way to get the alarm time?

Save it yourself somewhere persistent (file, database, SharedPreferences) when you set up the event. AlarmManager is write-only; you cannot retrieve information about scheduled events from it.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top