本文介绍了删除日历条目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我写了简单的code删除从Android的日历中的所有条目,但它并没有删除什么。
来源$ C $ C:
公共无效DeleteEvent(查看视图){
INT iNumRowsDeleted = 0;
乌里eventsUri = Uri.parse(内容://com.android.calendar/events);
光标CUR = getContentResolver()查询(eventsUri,NULL,NULL,NULL,NULL);
而(cur.moveToNext()){
长ID = cur.getLong(cur.getColumnIndex(_ ID));
Log.d(TAG,ID:+ ID);
乌里eventUri = ContentUris.withAppendedId(eventsUri,ID);
。iNumRowsDeleted = getContentResolver()删除(eventUri,NULL,NULL);
}
}
解决方案
我使用它进行删除:
私人无效deleteEvent(ContentResolver的解析器,乌里eventsUri,诠释calendarId){
光标光标;
如果(android.os.Build.VERSION.SDK_INT< = 7){//先进的Android 2.1
光标= resolver.query(eventsUri,新的String [] {_id},Calendars._id =+ calendarId,NULL,NULL);
}其他{// 8的是Android 2.2(升级Froyo)(http://developer.android.com/reference/android/os/Build.VERSION_$c$cS.html)
光标= resolver.query(eventsUri,新的String [] {_id},CALENDAR_ID =+ calendarId,NULL,NULL);
}
而(cursor.moveToNext()){
长事件ID = cursor.getLong(cursor.getColumnIndex(_ ID));
resolver.delete(ContentUris.withAppendedId(eventsUri,事件ID),NULL,NULL);
}
cursor.close();
}
我把它的东西是这样的:
乌里eventsUri;
INT OSVERSION = android.os.Build.VERSION.SDK_INT;
如果(OSVERSION< = 7){//先进的Android 2.1
eventsUri = Uri.parse(内容://日历/事件);
}其他{// 8的是Android 2.2(升级Froyo)(http://developer.android.com/reference/android/os/Build.VERSION_$c$cS.html)
eventsUri = Uri.parse(内容://com.android.calendar/events);
}
ContentResolver的解析器= this.getContentResolver();
deleteEvent(解析器,eventsUri,calendarId);
I wrote simple code for deleting all entries from android calendar,but it didn't delete nothing.
Source code:
public void DeleteEvent(View view){
int iNumRowsDeleted = 0;
Uri eventsUri = Uri.parse("content://com.android.calendar/events");
Cursor cur = getContentResolver().query(eventsUri, null, null, null, null);
while (cur.moveToNext()){
long id = cur.getLong(cur.getColumnIndex("_id"));
Log.d(TAG, "ID: " + id);
Uri eventUri = ContentUris.withAppendedId(eventsUri, id);
iNumRowsDeleted = getContentResolver().delete(eventUri, null, null);
}
}
解决方案
I use this for delete:
private void deleteEvent(ContentResolver resolver, Uri eventsUri, int calendarId) {
Cursor cursor;
if (android.os.Build.VERSION.SDK_INT <= 7) { //up-to Android 2.1
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "Calendars._id=" + calendarId, null, null);
} else { //8 is Android 2.2 (Froyo) (http://developer.android.com/reference/android/os/Build.VERSION_CODES.html)
cursor = resolver.query(eventsUri, new String[]{ "_id" }, "calendar_id=" + calendarId, null, null);
}
while(cursor.moveToNext()) {
long eventId = cursor.getLong(cursor.getColumnIndex("_id"));
resolver.delete(ContentUris.withAppendedId(eventsUri, eventId), null, null);
}
cursor.close();
}
I call it with something like this:
Uri eventsUri;
int osVersion = android.os.Build.VERSION.SDK_INT;
if (osVersion <= 7) { //up-to Android 2.1
eventsUri = Uri.parse("content://calendar/events");
} else { //8 is Android 2.2 (Froyo) (http://developer.android.com/reference/android/os/Build.VERSION_CODES.html)
eventsUri = Uri.parse("content://com.android.calendar/events");
}
ContentResolver resolver = this.getContentResolver();
deleteEvent(resolver, eventsUri, calendarId);
这篇关于删除日历条目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!