Hi I am working on demo app in which I am using AlarmManager
to schedule a service at 8:00 daily. I am using Calendar
to schedule service at 8:00 clock but this AlarmManager
is not running a service at scheduled time and even after 30 mins.
Below is my code to do this :-
public static void scheduleVerseNotificationService(Context mContext) {
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(mContext, DailyVerseNotificationService.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(mContext, 0, intent, 0);
// Set the alarm to start at approximately 08:00 morning.
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 8);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
}
TestService.java
public class TestService extends Service {
public TestService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
try {
// Code
} catch (Exception e) {
Logger.e(Constants.TAG, e.getMessage());
}
stopSelf();
}
}
AndroidManifest.xml
<service
android:name="com.service.TestService"
android:enabled="true"
android:exported="true" />
Thanks in advance.