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()) {
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"
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"
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.