Sunday, March 18, 2012

How to open Add Event screen of Android Calendar through Intent code?


I don't know about the other version's but it worked for android 2.3 and 3.0.........

 /*add an event through intent, this doesn't require any permission
          just send intent to android calendar*/



        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", false);
        intent.putExtra("rrule", "FREQ=DAILY");
        intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
        intent.putExtra("title", "A Test Event from android app");
        intent.putExtra("allDay", 0);
    //status: 0~ tentative; 1~ confirmed; 2~ canceled
        intent.putExtra("eventStatus", 1);
    //0~ default; 1~ confidential; 2~ private; 3~ public
        intent.putExtra("visibility", 0);
    //0~ opaque, no timing conflict is allowed; 1~ transparency, allow overlap of scheduling
        intent.putExtra("transparency", 0);
    //0~ false; 1~ true
        intent.putExtra("hasAlarm", 1);
        intent.putExtra("eventLocation", "@home");
        try {
    startActivity(intent);
    } catch (Exception e) {
    Toast.makeText(this.getApplicationContext(), "Sorry, no compatible calendar is found!", Toast.LENGTH_LONG).show();
    }

No comments:

Post a Comment