I am building a Calendar app to save events, show them and edit them with DatabaseHelper. I want to add alarm to these events but every I can find only setting alarm with Calendar import library. I want to set alarm in specific date and specific time.
Asked
Active
Viewed 96 times
1
-
1I don’t know Android, so can’t tell. I would hope that this exists or will come. If all else fails, you can convert. Get a `Calendar` object from `GregorianCalendar.from(yourLocalDate.atTime(yourLocalTime).atZone(ZoneId.systemDefault()))`. – Ole V.V. Jan 04 '23 at 13:23
-
thank you my friend, your solution dont work. – Chris Damianidis Jan 04 '23 at 14:19
-
[My code works fine.](https://ideone.com/5jfYlS) I don’t know what you did wring since it didn’t work for you. – Ole V.V. Jan 04 '23 at 15:35
-
I'll give it a try and I'll update with code reference – Chris Damianidis Jan 05 '23 at 08:04
1 Answers
0
I am building a Calendar app to save events show them and edit them with DatabaseHelper. I want to add alarm to these events but every I can find only setting alarm with Calendar import library. I want to set alarm in specific date and specific time.
Thanks to Ole V.V.
In this method i am creating a view for alert dialog, the function help me to convert date and time to start or cancel alarm:
public View setAllFields(View view,String id, String title, String comment, String date, String time, String alarm)
{
TextView id_lv_tv = view.findViewById(R.id.id_lv_tv);
TextView title_lv_tv = view.findViewById(R.id.title_lv_tv);
TextView comment_lv_tv = view.findViewById(R.id.comment_lv_tv);
TextView date_lv_tv = view.findViewById(R.id.date_lv_tv);
TextView time_lv_tv = view.findViewById(R.id.time_lv_tv);
ImageView alarmState = view.findViewById(R.id.alarmState);
id_lv_tv.setText(id);
title_lv_tv.setText(title);
comment_lv_tv.setText(comment);
date_lv_tv.setText(date);
time_lv_tv.setText(time);
Calendar c = GregorianCalendar.from(LocalDate.parse(date).atTime(LocalTime.parse(time)).atZone(ZoneId.systemDefault()));
if (alarm.equals("false"))
{
alarmState.setImageResource(R.drawable.alarm_off);
}else if (alarm.equals("true"))
{
alarmState.setImageResource(R.drawable.alarm_on);
}else
{
Toast.makeText(mContext, "Alarm set problem.", Toast.LENGTH_SHORT).show();
}
EventEdit ev = new EventEdit();
alarmState.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (alarm.equals("false"))
{
startAlarm(c);
Toast.makeText(mContext, "Alarm is set to: " + c.toString().trim(), Toast.LENGTH_SHORT).show();
alarmState.setImageResource(R.drawable.alarm_on);
}else if (alarm.equals("true"))
{
cancelAlarm(c);
Toast.makeText(mContext, "Alarm cancelled from : " + c.toString().trim(), Toast.LENGTH_SHORT).show();
alarmState.setImageResource(R.drawable.alarm_off);
}
}
});
return view;
}

Chris Damianidis
- 59
- 12