简体   繁体   English

在默认的Android日历中创建日历事件

[英]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. 我希望按钮可以在2013年3月3日上午10:00创建日历活动。 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. 您可以在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. 将上述代码放入按钮的onclick侦听器中。

In addition, you must add these calendar permissions in your manifest.xml: 另外,您必须在manifest.xml中添加以下日历权限:

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

Android Coder provides an easy way to finish this task Android Coder提供了一种轻松完成此任务的方法

In addition, you must add permission in your manifest.xml to use calendar event 此外,您必须在manifest.xml中添加权限才能使用日历事件

android:name="android.permission.READ_CALENDAR" 机器人:名字= “android.permission.READ_CALENDAR”

android:name="android.permission.WRITE_CALENDAR" 机器人:名字= “android.permission.WRITE_CALENDAR”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM