我想补充的日历事件在Android 4.0及以上版本的设备。 目前我使用下面的代码添加事件,
if (android.os.Build.VERSION.SDK_INT <= 7 )
{
Uri calendars = Uri.parse("content://calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
if (managedCursor.moveToFirst())
{
String calName;
String calId;
int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");
do
{
calName = managedCursor.getString(nameColumn);
calId = managedCursor.getString(idColumn);
Log.e("Calendar Id : ",""+calId+" : "+calName);
}
while (managedCursor.moveToNext());
if(calId != null)
{
try
{
Log.e("Calendar Id : ",""+calId+" : "+calName);
ContentValues event = new ContentValues();
event.put("calendar_id", calId);
event.put("title", summary);
event.put("description", summary);
event.put("eventLocation", "");
event.put("dtstart", startTime);
event.put("dtend", endTime);
event.put("allDay", allDayFlag);
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("hasAlarm", 1);
Uri eventsUri = Uri.parse("content://calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
Log.e("Event Res : ",""+url);
if(!url.equals(""))
Main.showErrorDialog(this, "Event Successfully Added ");
}
catch (Exception kwse)
{
Log.e("Exception 1 kwse ",""+kwse.toString());
}
}
}
}
else
{
Uri calendars= Uri.parse("content://com.android.calendar/calendars");
Cursor managedCursor = managedQuery(calendars, projection, null, null, null);
if (managedCursor.moveToFirst())
{
String calName;
String calId;
int nameColumn = managedCursor.getColumnIndex("name");
int idColumn = managedCursor.getColumnIndex("_id");
do
{
calName = managedCursor.getString(nameColumn);
calId = managedCursor.getString(idColumn);
Log.e("Calendar Id : ",""+calId+" : "+calName);
}
while (managedCursor.moveToNext());
if(calId != null)
{
try
{
Log.e("Calendar Id : ",""+calId+" : "+calName);
ContentValues event = new ContentValues();
event.put("calendar_id", calId);
event.put("title", summary);
event.put("description", summary);
event.put("eventLocation", "");
event.put("dtstart", startTime);
event.put("dtend", endTime);
event.put("allDay", allDayFlag);
event.put("eventStatus", 1);
event.put("visibility", 0);
event.put("hasAlarm", 1);
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Uri url = getContentResolver().insert(eventsUri, event);
Log.e("Event Res : ",""+url);
if(!url.equals(""))
Main.showErrorDialog(this, "Event Successfully Added ");
}
catch (Exception kwse)
{
Log.e("Exception 2 kwse ",""+kwse.toString());
}
}
}
}
上面的代码运行良好,直到Android 3.0的,但事件不会在Android 4.0的获取添加,这是一个投诉我从我的客户了。 我没有的Android 4.0的设备,所以我无法检查。
对于Android设备sdk version 7 and below
它,我们用的
Uri calendars = Uri.parse("content://calendar/calendars");
其中,作为sdk version above 7
,我们使用的
Uri calendars= Uri.parse("content://com.android.calendar/calendars");
难道,这就是同为Android 4.0的太是什么改变?