Вопрос

I am new to android development

I am trying to create a calendar which should be accessible both from the application I create and My android device's calendar application.

Let me first give my device information:

Android version : 4.3
API level of application: 18
Device: Asus nexus 7

I am creating calendar using code given below

ContentValues values = new ContentValues();
    values.put(
    Calendars.ACCOUNT_NAME,  "xyz@gmail.com");
    values.put(
          Calendars.ACCOUNT_TYPE,  CalendarContract.ACCOUNT_TYPE_LOCAL);
    values.put(
            Calendars.NAME,  "Test Calendar");

    values.put(
            Calendars.CALENDAR_DISPLAY_NAME,  "abc calendar");
    values.put(
          Calendars.CALENDAR_COLOR,  Color.YELLOW );
    values.put(
          Calendars.CALENDAR_ACCESS_LEVEL,  Calendars.CAL_ACCESS_OWNER);
    values.put(
            Calendars.OWNER_ACCOUNT,"xyz@gmail.com");
    values.put(
            Calendars.CALENDAR_TIME_ZONE, TimeZone.getDefault().getID());
    values.put(Calendars.VISIBLE, 1);
    Uri.Builder builder = 
          CalendarContract.Calendars.CONTENT_URI.buildUpon(); 
    builder.appendQueryParameter(
          Calendars.ACCOUNT_NAME,"xyz@gmail.com");
    builder.appendQueryParameter(
          Calendars.ACCOUNT_TYPE,  CalendarContract.ACCOUNT_TYPE_LOCAL);
    builder.appendQueryParameter(
          CalendarContract.CALLER_IS_SYNCADAPTER,  "true");
    Uri uri =this.cordova.getActivity().getContentResolver().insert(builder.build(), values);

    try {
        return calendarArray.put(new JSONObject().put("calendarURI", uri));
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return null;

when I run the code in application the calendar gets created but after that when I check my device, no new calendar created is visible there then.

I have tried like setting Calendars.VISIBLE property with value 1. and also searched for the solutions online but got nothing.

The code has been copied from the link

Please help me out here.

Это было полезно?

Решение

It was my fault, the calendar was added 9 times under the same name which was present from before the beginning of the moment I started creating application.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top