Reputation: 2531
I am creating a scheduler app in android which runs daily on user specified time here is the code please suggest why its not working
private void setAlarm(String targetCal){
Toast.makeText(MainActivity.this,"Alarm Set", Toast.LENGTH_LONG).show();
String[] Time=targetCal.split(":");
Intent intent = new Intent(getBaseContext(), AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getBaseContext(), RQS_1, intent, 0);
AlarmManager alarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Calendar timeOff = Calendar.getInstance();
//int days = Calendar.SUNDAY + (7 - timeOff.get(Calendar.DAY_OF_WEEK)); // how many days until Sunday
timeOff.set(Calendar.HOUR,Integer.valueOf(Time[0].trim()));
timeOff.set(Calendar.MINUTE,Integer.valueOf(Time[1].trim()));
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(), alarmManager.INTERVAL_DAY , pendingIntent);
}
Upvotes: 2
Views: 157
Reputation: 10969
Replace setRepeating
line with following:
Try:-
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(), 1000 * 60 * 60 * 60 * 24, pendingIntent);
Instead:-
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, timeOff.getTimeInMillis(), alarmManager.INTERVAL_DAY , pendingIntent);
Note: I just achieved this way and its works well fro me.
Upvotes: 1