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

时间:2012-08-17 02:19:21

标签: java android events date calendar

按下按钮时,我有以下代码可以执行某些操作。我希望能够让按钮在2013年3月3日上午10:00创建日历活动。感谢所有帮助。

代码:

@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()) {

2 个答案:

答案 0 :(得分:3)

您可以在Intent的帮助下打开日历。

以下是在日历应用程序中设置事件的代码。您只能在填写默认事件字段的情况下打开日历活动。

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);

将上面的代码放在按钮的onclick监听器中。

此外,您必须在manifest.xml中添加这些日历权限:

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

答案 1 :(得分:2)

Android Coder提供了一种完成此任务的简便方法

此外,您必须在manifest.xml中添加权限才能使用日历事件

机器人:名称= “android.permission.READ_CALENDAR”

机器人:名称= “android.permission.WRITE_CALENDAR”

相关问题