3

我使用 Android 2.3.5 使用以下代码创建了一个新日历:

    if(Build.VERSION.SDK_INT < 14)
    {
        ContentValues calendar = new ContentValues();

        calendar.put("_sync_account", "Com2Cal");
        calendar.put("_sync_account_type", "LOCAL");
        calendar.put("name", "Com2Cal");
        calendar.put("displayName", "Com2Cal");
        calendar.put("color", 0xFF008080);
        calendar.put("access_level", 700);
        calendar.put("sync_events", 1);
        calendar.put("timezone", TimeZone.getDefault().getID());
        calendar.put("ownerAccount", "Com2Cal");
        calendar.put("hidden", 0);
        Uri conentUri;

        if(Build.VERSION.SDK_INT >= 8)
        {
            conentUri = Uri.parse("content://com.android.calendar/calendars");
        }
        else
        {
            conentUri = Uri.parse("content://calendar/calendars");
        }

        Uri newRow = context.getContentResolver().insert(createCompleteUri(conentUri), calendar);

        Log.v(TAG, newRow.toString());
    }

private static Uri createCompleteUri(Uri uri)
{
    Uri.Builder b = uri.buildUpon();
    b.appendQueryParameter("caller_is_syncadapter", "true");
    b.appendQueryParameter("account_name", "Com2Cal");
    b.appendQueryParameter("account_type", "LOCAL");
    Uri calUri = b.build();
    Log.d("completeUri", calUri.toString());
    return calUri;
}

日历已成功创建,我可以在日历应用程序中看到它。但重启设备后,日历不再存在。我错过了什么?

4

0 回答 0