Calendar in an Android app

Asked

Viewed 3,103 times

0

I am trying to develop in my android app, a functionality from where I can consult, register, etc events in a calendar. I tried Calendarview and reached the point of clicking on a date and firing an event. My question is as follows. Would there be a simpler way to do this using Googlecalendar? How do I place an appointment on the date the event was created to know that that day has something registered? I read in Google Calendar but I got a little confused. I’m new in android and need help. Obridado

  • Bruno, there is a Google Calendar API, but it needs the internet and the access is done by REST to the google endpoint ( https://developers.google.com/google-apps/calendar/get_started). The API has a Java client. Another alternative is to use the Calendar Provider to access and modify your device’s local calendars without the need for internet. However it is only available for the SDK 14+, take a look at: http://developer.android.com/guide/topics/providers/calendar-provider.html. I haven’t used it yet, but soon I will need it and I think I will go through the Calendar Provider.

2 answers

3


You can open the calendar window as follows:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
startActivity(intent);

If you need to add dates use as follows:

//Cria uma intent para abertura de uma nova activity.
Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setType("vnd.android.cursor.item/event");

//Configurações do evento.
intent.putExtra(Events.TITLE, "Teste de Titulo");
intent.putExtra(Events.EVENT_LOCATION, "Local do evento");
intent.putExtra(Events.DESCRIPTION, "Teste de descrição");

//Configuração de data do evento
GregorianCalendar calDate = new GregorianCalendar(2014, 28, 08);
intent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME,
calDate.getTimeInMillis());
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME,
calDate.getTimeInMillis());

//Marca o evento como dia inteiro.
intent.putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, true);

//Define se será repetido
intent.putExtra(Events.RRULE, "FREQ=WEEKLY;COUNT=11;WKST=SU;BYDAY=TU,TH");

//Marca como privado e como ocupado.
intent.putExtra(Events.ACCESS_LEVEL, Events.ACCESS_PRIVATE);
intent.putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); 

If you want to use inside your application, you will have to do different. There is this third party library that I found very interesting and is beautiful, it can help you.

https://github.com/roomorama/Caldroid

Hug.

  • Remembering that using the CalendarContracts requires the SDK 14+, and Caldroid does not access the User calendar, in the repository itself it says: "Caldroid is Simply an UI library and it does not connect to user Calendar database or fetch any user’s Events. If your app wants to display These Events on Caldroid".

  • I found another post interesting and very promising. But I did not test to see if everything works, I hope to test soon and then put the result... but if anyone wants to test follow the link: Here

0

I don’t know if it’s what you need, but I also had to work with calendar and I found this library very good:

https://github.com/shrikanth7698/Collapsible-Calendar-View-Android

final CollapsibleCalendar collapsibleCalendar = findViewById(R.id.calendarView);
    collapsibleCalendar.setCalendarListener(new CollapsibleCalendar.CalendarListener() {

        @Override
        public void onDaySelect() {
            Day day = viewCalendar.getSelectedDay();
            Log.i(getClass().getName(), "Selected Day: "
                    + day.getYear() + "/" + (day.getMonth() + 1) + "/" + day.getDay());
        }

        @Override
        public void onItemClick(View view) {

        }

        @Override
        public void onDataUpdate() {

        }

        @Override
        public void onMonthChange() {

        }

        @Override
        public void onWeekChange(int i) {

        }
    });
  • While this link may answer the question, it is best to include the essential parts of the answer here and provide the link for reference. Replies per link only can be invalidated if the page with the link is changed. - Of Revision

  • @Isac modified response

Browser other questions tagged

You are not signed in. Login or sign up in order to post.