1

新しいカレンダーを追加しました:

ContentValues event2= new ContentValues();          
event.put("name", "My calendar");
                    event.put("displayName", "My new calendar");
                    event.put("hidden",0);  
                            Uri url2 = getContentResolver().insert(calendarUri, event);

すべてのカレンダーを一覧表示すると、新しいカレンダーが表示されますが、ネイティブのカレンダー APP がクラッシュし、新しいカレンダーを表示できなくなりました。ここで検索し、いくつかの方法をテストしました。

Uri uri1=ContentUris.withAppendedId(calendarUri, calId);
  int url3 = getContentResolver().delete(uri1,"_id="+calId",projection);
  int url2 = getContentResolver().delete(calendarUri,"_id=3",projection);

しかし、常にエラーが表示されます: 名前は空であってはなりません :null (射影は id と名前を持つ配列文字列です)

何か案が?

4

2 に答える 2

0

これを試して:

getContentResolver.delete(ContentUris.withAppendedId(CalendarContract.Calendars.CONTENT_URI, id), null, null);

id削除するカレンダーの ID はどこにありますか。

テストはしていませんが、イベントでは機能します。

于 2014-01-13T22:28:26.883 に答える
0

少し遅いかもしれませんが:

Uri evuri = CalendarContract.Calendars.CONTENT_URI;
//substitue your calendar id into the 0
long calid = 0; 
Uri deleteUri = ContentUris.withAppendedId(evuri, calid);
getActivity().getContentResolver().delete(deleteUri, null, null);

私のために働きます。

または、カレンダー ID がわからない場合:

Uri evuri = CalendarContract.Calendars.CONTENT_URI;
Cursor result = getActivity().getContentResolver().query(evuri, new String[] {CalendarContract.Calendars._ID, CalendarContract.Calendars.ACCOUNT_NAME, CalendarContract.Calendars.CALENDAR_DISPLAY_NAME}, null, null, null);
while (result.moveToNext()) 
{
     if(result.getString(2).equals("YOUR CALENDAR NAME"))
     {
         long calid = result.getLong(0);
         Uri deleteUri = ContentUris.withAppendedId(evuri, calid);
         getActivity().getContentResolver().delete(deleteUri, null, null);
     }
}

もちろん、CalendarContract.Calendars.ACCOUNT_NAME を見つけるのは冗長かもしれないので、削除してください。(実際にはオーバーヘッドはほとんどありません)

于 2014-01-10T18:02:58.013 に答える