を削除されません。 title
とstart date
イベントがすでに(重複を持ってしないように)それを追加する前に、カレンダーに存在するかどうかをチェックするためのコードを検索します。私は(カレンダーを使用して)手動でカレンダーからイベントを削除した場合、イベントはカレンダーから消え(私はすべての私のカレンダーを表示していますし、カレンダーアプリケーションでそれを見ることができない)ではなく、データベースから:私の問題は、ということです。私が理解できない別のことは、プログラムでイベントを削除しようとしたが、削除されていないということです。ここで削除イベントは、私は私のアプリがユーザーのカレンダーにリマインダーを追加しようとしています
は私のコードスニペットです:
Cursor cur = null;
ContentResolver cr = getContentResolver();
String calUriString = "content://com.android.calendar/events";
Uri cal=Uri.parse(calUriString);
String[] EVENT_PROJECTION=new String[]{"calendar_id","title","dtstart","_id"};
String selection = "((" + "calendar_id" + " = 1) AND ("
+ "title" + " LIKE '"+name+"') AND ("
+ "dtstart" + " = "+String.valueOf(c.getTimeInMillis())+"))";
cur = cr.query(cal, EVENT_PROJECTION, selection, null, null);
boolean found=false;
if(cur!=null)
if(cur.moveToFirst()){
DatabaseUtils.dumpCursor(cur);/*Just to view my results (which always include the deleted events)*/
do{
if(cur.getString(1).equals(name)){
/*I use this part to try to remove the events manually*/
Uri eventUri =ContentUris.withAppendedId(cal, Long.valueOf(cur.getString(3)));
String reminderUriString = "content://com.android.calendar/reminders";
Uri remUri =Uri.parse(reminderUriString);
cr.delete(remUri, "event_id="+cur.getString(3), null);
cr.delete(eventUri, null, null);
/*It is not working also*/
Toast.makeText(getApplicationContext(), "Event already exists in Calendar", Toast.LENGTH_LONG).show();
found=true;
//break;
}
}while(cur.moveToNext());
}
cur.close();
if(found){
/*Event is found even if I remove it from the Calendar manually and even if I remove it programmatically using cr.delete()*/
}
else{
values.put("calendar_id",1); /*I am using the same Calendar that I query, or is this wrong*/
values.put("title", name);
/*More values are added*/
Uri calendarUri = cr.insert(cal, values);
long eventID = Long.parseLong(calendarUri.getLastPathSegment());
String reminderUriString = "content://com.android.calendar/reminders";
ContentValues reminderValues = new ContentValues();
reminderValues.put("event_id", eventID);
reminderValues.put("minutes", 5);
reminderValues.put("method", 1);
Uri reminderUri = getApplicationContext().getContentResolver().insert(Uri.parse(reminderUriString), reminderValues);
}
はなぜイベントはカレンダーアプリケーションからそれらを削除した後になお存在していると、なぜ私も、プログラムでそれを削除することはできませんよ?
更新 問題は、挿入と削除にcalendar_id=1
を使用した場合のみです。その他calendar_id
はうまく動作します。
更新2 私はSamsung Galaxy S1のコードをテストして正常に動作しています。それは三星ギャラクシーS3の問題だと思う(私は問題がある、私はそれがS-プランナーアプリケーションのバグだと思う)
アプリを再起動した場合、削除されたイベントはまだそれに表示されていますか? – NathanTempelman
はい、私は電話を再起動しても、彼らはカレンダーアプリケーションに表示されますが、それでもContentResolverのに表示されません。クエリ() –
@Mohamed_AbdAllahこれが当てはまる場合は確かに言えませんが、類似の問題はジャンルや音楽のクエリで確認できます。あなたはバグ=/ – Warpzit