use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class EventFragment method cancelAlarm.
private void cancelAlarm() {
// cancel the alarm
AlarmReceiver alarmReceiver = new AlarmReceiver();
String subTitle = "";
if (mScheduleItem.getStartAt() != null) {
subTitle = DateHelper.getDateTimeString(getContext(), mScheduleItem.getStartAt());
}
alarmReceiver.cancelAlarm(getContext(), mScheduleItem.getId(), mScheduleItem.getTitle(), subTitle);
// remove it from the database
if (mDatabaseHandler == null) {
mDatabaseHandler = new DatabaseHandler(getActivity());
}
try {
mDatabaseHandler.open();
int id = mDatabaseHandler.getRowIdByAssignmentId(mScheduleItem.getId());
int result = mDatabaseHandler.deleteAlarm(id);
mDatabaseHandler.close();
} catch (SQLException e) {
// couldn't delete the alarm, so it will remain in the database. But the actual
// alarm should have been canceled above.
}
}
use of com.instructure.parentapp.database.DatabaseHandler in project instructure-android by instructure.
the class AlarmReceiver method cancelAlarm.
public void cancelAlarm(Context context, long assignmentId, String title, String subTitle) {
// need to create an intent that matches the one we want to cancel
Intent intent = new Intent(context, AlarmReceiver.class);
intent.putExtra(Const.TITLE_TEXT, title);
intent.putExtra(Const.SUBTITLE_TEXT, subTitle);
int alarmId = -1;
DatabaseHandler mDatabaseHandler = new DatabaseHandler(context);
try {
mDatabaseHandler.open();
alarmId = mDatabaseHandler.getRowIdByAssignmentId(assignmentId);
mDatabaseHandler.close();
} catch (SQLException e) {
}
PendingIntent sender = PendingIntent.getBroadcast(context, alarmId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
sender.cancel();
alarmManager.cancel(sender);
}
Aggregations