简体   繁体   中英

Adding event to Android calendar

i am trying to add calendar event to android calendar , but keep getting this message "Before you can add an event ,you must add at least one Calendar account to your device and make a calendar visible.Touch Add Account to add an Account(if you just added an account wait for it to finish syncing and try again).Or touch cancel and make sure at least one calendar is visible" i added calendar account when i was prompted for it but it didn't help.although i opened calender manualy it didn't help also.

 Intent intent = new Intent(Intent.ACTION_INSERT).setData(Events.CONTENT_URI)    .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, beginTime.getTimeInMillis())


            .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endTime.getTimeInMillis())
            .putExtra(Events.TITLE, "Yoga")
            .putExtra(Events.DESCRIPTION, "Group class")
            .putExtra(Events.EVENT_LOCATION, "The gym")
            .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY)
           ;
    startActivity(intent);

can someone tell me what is the problem ?

First, you have to add an account to your phone Second, add a new calendar where you set the account If you made the calendar successfully you can add the events to it

Calendar and events are handled by the ContentResolver, and can be added by .insert() method. The account can be added by the AccountManager .addAccountExplicitly()

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