i am developing a scheduling app in which user selects a time from listview like 9:30 P.M or any time which is in the list and hits the button stop schedule, what i want want to stop schedule at 9:30 when its 9:30 (i will cal update method in database and update the user end time) or which the user selects from the list, user can also stop multiple schedules at a same time, i tried to use Scheduling Repeating Alarms but did not find any solution. Please help me how can i do this?.
This is code i am making alarm for specific time
@TargetApi(Build.VERSION_CODES.N)
public void scheduleAlarm(View view, String timeEnd,String id) {
StringTokenizer tokens = new StringTokenizer(timeEnd, ":");
String first = tokens.nextToken();
String second = tokens.nextToken();
StringTokenizer token = new StringTokenizer(second, " ");
String two = token.nextToken(); // just changing given time into like 9:30 to 9 and 30
AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
android.icu.util.Calendar calendar = android.icu.util.Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(android.icu.util.Calendar.HOUR_OF_DAY, Integer.parseInt(first));
calendar.set(android.icu.util.Calendar.MINUTE, Integer.parseInt(two));
Intent intent = new Intent(getApplicationContext(), AlarmReciever.class);
intent.putExtra("ID",id);
intent.putExtra("EndTime",timeEnd);
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), sender);
}
And this is the Broadcast Receiver its works but broadcast class trigger at same time when i give the time to alarm schedule not on the given time.
public class AlarmReciever extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
SQLITEDBTABLE sqLiteDatabase = new SQLITEDBTABLE(context);
String id = intent.getStringExtra("ID");
String time_end = intent.getStringExtra("EndTime");
sqLiteDatabase.update(time_end, id);
/* sqLiteDatabase.deleteOlderData(laterId);
sqLiteDatabase.deleteInactive(laterId);
sqLiteDatabase.updateEmployee(laterId, "Inactive");*/
//Toast.makeText(context, "Alarm Triggered and SMS Sent", Toast.LENGTH_LONG).show();
}
}