Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It is for 2.2+ version only</p> <p>I used the code below to add event in calender</p> <pre><code>if (Build.VERSION.SDK_INT &gt;= 14) { Calendar cal = Calendar.getInstance(); 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, "A Test Event from android app by Neha ") . putExtra("beginTime", cal.getTimeInMillis()) .putExtra("allDay", true) .putExtra("rrule", "FREQ=YEARLY") .putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000) .putExtra(Events.AVAILABILITY, Events.AVAILABILITY_BUSY); startActivity(intent); } else { Calendar cal = Calendar.getInstance(); Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.android.cursor.item/event"); intent.putExtra("beginTime", cal.getTimeInMillis()); intent.putExtra("allDay", true); intent.putExtra("rrule", "FREQ=YEARLY"); intent.putExtra("endTime", cal.getTimeInMillis() + 60 * 60 * 1000); intent.putExtra("title", "A Test Event from android app by Neha"); startActivity(intent); } </code></pre> <p>and the code below i used to edit event</p> <pre><code>long calendarEventID = GetMaxID(); Uri uri = Uri.parse("content://com.android.calendar/events/" + String.valueOf(calendarEventID)); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(uri); intent.putExtra("beginTime", startDate); intent.putExtra("endTime", endDate); startActivity(intent); </code></pre> <p>and GetMaxId as</p> <p>public long GetMaxID() {</p> <pre><code> ContentResolver contentResolver = getContentResolver(); Uri local_uri; local_uri = Uri.parse("content://com.android.calendar/events"); Cursor cursor = contentResolver.query(local_uri, new String[] { "_id as max_id", "dtstart", "dtend" }, null, null, "_id"); cursor.moveToFirst(); long max_val = cursor.getLong(cursor.getColumnIndex("max_id")); startDate = cursor.getLong(cursor.getColumnIndex("dtstart")); endDate = cursor.getLong(cursor.getColumnIndex("dtend")); return max_val + 1; } </code></pre> <p>and put the permission in menifest as </p> <pre><code>&lt;uses-permission android:name="android.permission.WRITE_CALENDAR"&gt;&lt;/uses-permission&gt; &lt;uses-permission android:name="android.permission.READ_CALENDAR"&gt;&lt;/uses-permission&gt; </code></pre> <p>Hope it would help to someone also.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload