androidxamarinalarmmanagerrepeatingalarm

how to make Alarm repeats for particular time interval in Xamarin Droid project?


Using Xamarin Droid, i have created an alarm application. Setting alarm for the particular time was worked good. when i try to repeat the alarm for the particular time interval, it fails to alarm at the particular time. the application needs to alarm even the application in sleep. The below code was i tried in Xamarin Droid project for setting and repeating alarm. please direct me in right way to achieve my solution for repeating alarm!.

Setting alarm for particular time:

 manager.Set(AlarmType.ElapsedRealtime, SystemClock.ElapsedRealtime() + 60 * 1000 * int.Parse(notifytime), pendingIntent);

My need is to repeat the alarm for every 15 min from the alarm rang.

 manager.SetRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime()+10, AlarmManager.IntervalFifteenMinutes, pendingIntent);

Thanks in advance.


Solution

  • change this line...

    manager.SetRepeating(AlarmType.ElapsedRealtimeWakeup, SystemClock.ElapsedRealtime()+10, AlarmManager.IntervalFifteenMinutes, pendingIntent);
    

    to

     manager.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(),15*60*1000, pintent);
    

    also add this

    <uses-permission android:name="android.permission.WAKE_LOCK" />
    

    to your AndroidManifest.xml file as #Avi Cherry said !!

    schedule a repeating alarm