3

I am writing a event searching. We added some webservices now the events wont push automatically to the calendar. The auto-add feature does not work anymore heres the code please ask as many questions as possible i do have the permissions in the android manifest. everything ive see it should be good to go heres where im calling it and what the code is currently. Runs no errors just never shows up in calendar

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity().getApplicationContext());
AutoAddFlag = preferences.getBoolean("auto_calendar_preference", false);
calendarButton.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(AutoAddFlag)
            autocreate();
        else
            createEvent();

    }
});

public void autocreate(){
    //need to set the real times
    Calendar beginTime = Calendar.getInstance();

    beginTime.set(2015,6,10,10,10);
    //need to set the real end time
    Calendar endTime = Calendar.getInstance();
    endTime.set(7, 7, 30, 1, 30);

    //create content that will go into the calendar
    ContentValues calEvent = new ContentValues();
    //create ability to insert into the calendar
    ContentResolver cr = this.getActivity().getContentResolver();
    //where/when/id_for_insert/start_time/end_time/time_zone
    //need address/description
    calEvent.put(CalendarContract.Events.CALENDAR_ID,1); // XXX pick)


    calEvent.put(CalendarContract.Events.DTSTART, beginTime.getTimeInMillis());
    calEvent.put(CalendarContract.Events.DTEND, beginTime.getTimeInMillis());
    calEvent.put(CalendarContract.Events.EVENT_TIMEZONE, TimeZone.getDefault().getID());
    calEvent.put(CalendarContract.Events.TITLE, "titorejwl;e");
    calEvent.put(CalendarContract.Events.EVENT_LOCATION, obj.getVenue_name());
    calEvent.put(CalendarContract.Events.DESCRIPTION, obj.getNotes());
    Uri eventsUri = Uri.parse("content://com.android.calendar/events");
    Uri EVENTS_URI = Uri.parse(CalendarContract.Events.CONTENT_URI.toString());
    Uri uri = cr.insert(EVENTS_URI, calEvent);
    //get id for reminders


    Toast.makeText(getActivity(), uri + " was added to the Calendar", Toast.LENGTH_SHORT).show();
    //Toast.makeText(getActivity(), obj.getDescription() + " was added to the Calendar", Toast.LENGTH_SHORT).show();

}
Will
  • 24,082
  • 14
  • 97
  • 108
  • All I know is that the whole calendar api on Android is buggy and unpredictable. That comment doesn't help you but rest assured that you're not alone with this ;) – fweigl Jul 09 '15 at 21:56
  • `Android Studio wont insert calendar event` of course it won't. Androd Studio is an IDE... sigh.... – Marcin Orlowski Jul 09 '15 at 22:21
  • Thanks for being a smart ass i love it. But found out code works just not on lg g4 so first guys comments might prove useful – brandon snow Jul 09 '15 at 23:20

0 Answers0