Error creating Android calendar

I am trying to add my own calendar in android using the following code. I also granted permission to read the entry in the manifest.

and my mistake is: "Error creating calendar, name should not be empty: null" , although I specified the name ...

any, please help me solve it, as well as provide a link to a working solution for creating a calendar in android.

final Uri calUri = Uri.parse("content://com.android.calendar/calendars"); android.accounts.Account account; ContentValues vals = new ContentValues(); vals.put("_id", 1); vals.put("_sync_account_type", "ACCOUNT_TYPE_LOCAL"); vals.put("name","sachin" ); vals.put("displayName","my_Cal"); vals.put("color", 14417920); vals.put("access_level", 700); vals.put("selected", 1); vals.put("sync_events", 1); vals.put("timezone", "GMT"); vals.put("hidden", 0); Uri result= getContentResolver().insert(calUri, vals); System.out.println(result); 
+4
source share
2 answers

You should try something like this:

 vals.put(Calendar.Calendars._SYNC_ACCOUNT_TYPE, "ACCOUNT_TYPE_LOCAL"); vals.put(Calendar.Calendars.NAME,"sachin"); vals.put(Calendar.Calendars.DISPLAY_NAME,"my_Cal"); vals.put(Calendar.Calendars.COLOR, 14417920); vals.put(Calendar.Calendars.ACCESS_LEVEL, 700); vals.put(Calendar.Calendars.SELECTED, 1); vals.put(Calendar.Calendars.SYNC_EVENTS, 1); vals.put((Calendar.Calendars.TIMEZONE, "GMT"); vals.put(Calendar.Calendars.HIDDEN, 0); 
0
source
 public String createCalendar(String AccountName, String CalendarName,String Color) { try { Uri target = Uri.parse("content://com.android.calendar/calendars"); target = target.buildUpon() .appendQueryParameter("caller_is_syncadapter", "true") .appendQueryParameter("account_name", AccountName) .appendQueryParameter("account_type", "com.google").build(); // String calUriString = "content://calendar/calendars"; ContentValues values = new ContentValues(); values.put("name", AccountName); values.put("account_name", AccountName); values.put("account_type", "com.google"); values.put("calendar_displayName", CalendarName); values.put("calendar_color", Color); values.put("calendar_access_level", "700"); Uri calendarUri = getContentResolver().insert(target, values); Log.v("calendar Uri", calendarUri.toString()); String newCalID = calendarUri.toString().substring( calendarUri.toString().lastIndexOf("/") + 1, calendarUri.toString().indexOf("?")); Log.v("calendar Id", newCalID); return newCalID; } catch (Exception e) { System.out.println(e.toString()); return null; } } 
+2
source

Source: https://habr.com/ru/post/1443194/


All Articles