如果有多个日历,如何创建事件-Android

如果有多个日历,如何创建事件-Android,android,calendar,android-calendar,Android,Calendar,Android Calendar,我试图创建一个有问题的日历事件。下面的代码是工作文件,但问题是当我启动活动时,它的pop两个日历(com.android.calendar,com.google.android.calendar) 如何选择其中任何一个 Calendar cal = Calendar.getInstance(); Intent intent = new Intent(Intent.ACTION_EDIT); intent.setType("vnd.and

我试图创建一个有问题的日历事件。下面的代码是工作文件,但问题是当我启动活动时,它的pop两个日历(com.android.calendar,com.google.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", true);
        intent.putExtra("rrule", "FREQ=YEARLY");
        intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
        intent.putExtra("title", "A Test Event from android app");
        startActivity(intent);

看起来您已经在设备上安装了两个日历应用程序,但通常情况并非如此,通常设备默认有一个日历应用程序

我建议您在这种情况下不要做任何事情,原因如下

1) Generally device having only one calendar app
2) If you choose a particular calendar then the devices which not installed your specified calendar won't able to use you app.
3) If person has installed two calendar let him decide which he want to use to add event, which is recommended by Google.

您可以创建选择器,并允许用户选择要在哪个日历应用程序上保存事件

Intent.createChooser(intent, "Choose 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", true);
intent.putExtra("rrule", "FREQ=YEARLY");
intent.putExtra("endTime", cal.getTimeInMillis()+60*60*1000);
intent.putExtra("title", "A Test Event from android app");
startActivity(Intent.createChooser(intent, "Choose Calendar"));

com.android.calendar、com.google.android.calendar都是谷歌日历,这就是为什么我不知道如何处理它。我可以建议简单的解决方案卸载一个谷歌日历。因为一般人没有两个谷歌日历,你不需要做任何事情。这些是系统应用。我想我们也不能删除。通常只有一个日历系统应用。已尝试卸载两个或仅卸载一个??否,因为两个日历名称相同。当我执行代码时,它说没有应用程序:(