ScorpioBlue
ScorpioBlue

Reputation: 187

Create calendar event in the default android calendar

I have the following code to do something when a button is pressed. I would like to be able to have the button create a calendar event for March 3rd, 2013 at 10:00 am. All help is appreciated.

Code:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    //Button button = (Button)findViewById(R.id.button1);
   // button.setOnClickListener(this);
    final CheckBox checkBox = (CheckBox) findViewById(R.id.checkBox1);
    final CheckBox checkBox2 = (CheckBox) findViewById(R.id.checkBox2);


    final Button button = (Button) findViewById(R.id.button1);
    button.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v) {


             if (checkBox.isChecked()) {

Upvotes: 2

Views: 2026

Answers (2)

rajpara
rajpara

Reputation: 5203

You can open calendar with help of Intent.

Below is code for setting event in Calendar application. you can only open Calendar activity with default Event field filled.

Intent intent = new Intent(Intent.ACTION_EDIT);
intent.setType("vnd.android.cursor.item/event");
intent.putExtra("title", "Some title");
intent.putExtra("description", "Some description");
intent.putExtra("beginTime", eventStartInMillis);
intent.putExtra("endTime", eventEndInMillis);
startActivity(intent);

Put above code in your button's onclick listener.

In addition, you must add these calendar permissions in your manifest.xml:

android:name="android.permission.READ_CALENDAR"
android:name="android.permission.WRITE_CALENDAR"

Upvotes: 3

Klaudo
Klaudo

Reputation: 700

Android Coder provides an easy way to finish this task

In addition, you must add permission in your manifest.xml to use calendar event

android:name="android.permission.READ_CALENDAR"

android:name="android.permission.WRITE_CALENDAR"

Upvotes: 2

Related Questions