Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/193.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android api级别大于8的情况下添加日历事件?_Android_Calendar_Cursor_Android Contentresolver - Fatal编程技术网

如何在android api级别大于8的情况下添加日历事件?

如何在android api级别大于8的情况下添加日历事件?,android,calendar,cursor,android-contentresolver,Android,Calendar,Cursor,Android Contentresolver,如何在android api级别大于8的情况下添加日历事件 ContentResolver cr = getContentResolver(); Cursor cursor = null; try{ if(Build.VERSION.SDK_INT >= 8){ cursor=cr.query(Uri.parse("content://com.android.calendar/reminders"), null, null, null, null); }el

如何在android api级别大于8的情况下添加日历事件

ContentResolver cr = getContentResolver();
Cursor cursor = null;
try{
    if(Build.VERSION.SDK_INT >= 8){
        cursor=cr.query(Uri.parse("content://com.android.calendar/reminders"), null, null, null, null);
    }else {
        cursor=cr.query(Uri.parse("content://calendar/reminders"), null, null, null, null);
    }
但我在api级别8到10中得到了游标null,但它在api 4.2上工作。
如何为日历事件或提醒获取此光标?

根据您的问题和代码,我不清楚您是否要实际添加日历事件或查询现有日历事件。如果确实要添加日历事件,则需要使用意图。例如:

Intent calendarIntent = new Intent(Intent.ACTION_INSERT);
calendarIntent.setType("vnd.android.cursor.item/event");
calendarIntent.putExtra(Events.TITLE, "the title");
calendarIntent.putExtra(Events.EVENT_LOCATION, "the location");
calendarIntent.putExtra(Events.DESCRIPTION, "some description");

calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, start);
calendarIntent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, end);
startActivity(calendarIntent);

其中“开始”和“结束”是表示日期的长值。

我想在最低api级别8上添加ot get Calendar事件。这段代码至少需要api 14。你说得对,我很抱歉。据我所知,在蜂巢之前没有用于添加日历事件的官方API。即使您发布的URI有效,它在所有设备上也可能不一致。如果你真的找到了解决办法,我很想知道它是什么。在我自己的应用程序中,我允许用户将事件添加到他们的日历中,对于较旧的API级别,我只是禁用了此功能。