简体   繁体   中英

How to read calendar event for the week using intents in Android Studio?

Hey I'm making a voice assistant application, and want to let the user know about upcoming events so I want to read events using intents. I have been trying to read google calendar API and figure out but I couldn't quite get it. I will greatly appreciate anyone who can help me out...

I have implemented a way to create a new event using:

Intent intent = new Intent(Intent.ACTION_INSERT);
intent.setData(CalendarContract.Events.CONTENT_URI);
intent.putExtra(CalendarContract.Events.TITLE, titleString);
intent.putExtra(CalendarContract.Events.DESCRIPTION, description);
intent.putExtra(CalendarContract.Events.EVENT_LOCATION, "Worldwide");
intent.putExtra(CalendarContract.Events.ALL_DAY, true);
intent.putExtra(Intent.EXTRA_EMAIL, "test@gmail.com");
intent.putExtra(CalendarContract.Events.EVENT_TIMEZONE, timeZone.getID());
intent.putExtra(CalendarContract.Events.HAS_ALARM, 1);

Try to do in this way

Cursor cursor = context.getContentResolver().query(
                        Uri.parse("content://com.android.calendar/events"),
                        new String[] { "calendar_id", "title", "description","dtstart", 
                        "dtend", "eventLocation" }, null, null, null);
cursor.moveToFirst();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM