i recently upgraded my phone to android m and i am trying to get my alarm app working. I have always been using set and setExact to schedule my alarms but now in android m they seems to be obsolete.
I have tried setExactAndAllowIdle and setAlarmClock and they work fine when the alarm is set maximum about an hour into the future but when i set the alarms further into the future(for example the next morning) they are newer executed.
How do i implement the same functionality in android m? My Alarm Register Below.
package com.lindev.newday.legacy;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.os.Build;
public class NDLegacyAlarmHelper {
public static NDLegacyAlarmRegisterMethod RegisterAlarm(long time, PendingIntent pendingIntent, AlarmManager alarmManager)
{
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
{
//alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
AlarmManager.AlarmClockInfo alarmClock = new AlarmManager.AlarmClockInfo(time, pendingIntent);
alarmManager.setAlarmClock(alarmClock, pendingIntent);
return NDLegacyAlarmRegisterMethod.setExactAndAllowWhileIdle;
}
else if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)
{
alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent);
return NDLegacyAlarmRegisterMethod.setExact;
}
else
{
alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
return NDLegacyAlarmRegisterMethod.set;
}
}
}