I am working on repeating alarm . problem is that my repeat alarm only runs for one time only on set time but not repeat on that time next day. If it is 5/28/2015 and time is 1:40PM and I set alarm to 8:30am with repeating mode then it should repeat everyday on 8:30am but problem is that it runs on 5/29/2015 on 8:30AM but will not run on 5/30/2015 at 8:30AM and further on. Here is my code:
if(AM_PMSet!=null)
{
Calendar gcClone = Calendar.getInstance();
Calendar gc = (Calendar) gcClone.clone();
//Log.e("-------------------","---"+hourSet);
gc.set( Calendar.HOUR_OF_DAY, hourSet );
gc.set( Calendar.MINUTE, minuteSet);
gc.set( Calendar.SECOND, 0 );
gc.set( Calendar.MILLISECOND, 0 );
if(gc.compareTo(gcClone) <= 0){
//Today Set time passed, count to tomorrow
gc.add(Calendar.DATE, 1);
}
if(repeatBool==true){
long timeToAlarm = gc.getTimeInMillis();
PendingIntent pendingIntent;
Intent myIntent = new Intent(AyatRuqyaActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(AyatRuqyaActivity.this, RQS_1, myIntent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, gc.getTimeInMillis(), pendingIntent);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeToAlarm,24*60*60*1000, pendingIntent);
settings = getSharedPreferences(PREFS_NAME, 0);
settings.edit().putBoolean("setAlarm", true).commit();
settings.edit().putInt("setAlarmHour", hourSet).commit();
settings.edit().putInt("setAlarmMinute", minuteSet).commit();
settings.edit().putInt("setRepeating", 1).commit();
}else if(repeatBool==false){
PendingIntent pendingIntent;
Intent myIntent = new Intent(AyatRuqyaActivity.this, MyReceiver.class);
pendingIntent = PendingIntent.getBroadcast(AyatRuqyaActivity.this, RQS_1, myIntent,PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, gc.getTimeInMillis(), pendingIntent);
settings = getSharedPreferences(PREFS_NAME, 0);
settings.edit().putBoolean("setAlarm", true).commit();
settings.edit().putInt("setAlarmHour", hourSet).commit();
settings.edit().putInt("setAlarmMinute", minuteSet).commit();
settings.edit().putInt("setRepeating", 0).commit();
}
}
In my Receiver Class I am calling a service
public void onReceive(Context context, Intent intent)
{
playIntent = new Intent(context, MusicService.class);
playIntent.putExtra("width", 0);
playIntent.putExtra("height", 0);
playIntent.putExtra("densitydpi", 0);
playIntent.putExtra("fromMyReceiver", "true");
context.startService(playIntent);
}
Manifest
<service
android:name=".MusicService"
android:enabled="true" />
<receiver android:name=".MyReceiver"
android:process="remote" />