91超碰碰碰碰久久久久久综合_超碰av人澡人澡人澡人澡人掠_国产黄大片在线观看画质优化_txt小说免费全本

溫馨提示×

Java CalendarProvider類使用實例

小云
81
2023-09-28 10:03:32
欄目: 編程語言

下面是一個使用Java CalendarProvider類的示例:

import android.content.ContentResolver;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.provider.CalendarContract;
public class CalendarProviderExample {
private static final String CALENDAR_NAME = "My Calendar";
public static void createCalendar(ContentResolver contentResolver) {
ContentValues contentValues = new ContentValues();
contentValues.put(CalendarContract.Calendars.ACCOUNT_NAME, "your_account_name");
contentValues.put(CalendarContract.Calendars.ACCOUNT_TYPE, "your_account_type");
contentValues.put(CalendarContract.Calendars.NAME, CALENDAR_NAME);
contentValues.put(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME, CALENDAR_NAME);
contentValues.put(CalendarContract.Calendars.CALENDAR_COLOR, 0x00FF00);
contentValues.put(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL, CalendarContract.Calendars.CAL_ACCESS_OWNER);
contentValues.put(CalendarContract.Calendars.OWNER_ACCOUNT, "your_owner_account");
contentValues.put(CalendarContract.Calendars.VISIBLE, 1);
contentValues.put(CalendarContract.Calendars.SYNC_EVENTS, 1);
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
calendarUri = calendarUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "your_account_name")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "your_account_type")
.build();
contentResolver.insert(calendarUri, contentValues);
}
public static void deleteCalendar(ContentResolver contentResolver) {
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
calendarUri = calendarUri.buildUpon()
.appendQueryParameter(CalendarContract.CALLER_IS_SYNCADAPTER, "true")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_NAME, "your_account_name")
.appendQueryParameter(CalendarContract.Calendars.ACCOUNT_TYPE, "your_account_type")
.build();
String selection = CalendarContract.Calendars.NAME + "=?";
String[] selectionArgs = new String[]{CALENDAR_NAME};
contentResolver.delete(calendarUri, selection, selectionArgs);
}
public static void queryCalendar(ContentResolver contentResolver) {
Uri calendarUri = CalendarContract.Calendars.CONTENT_URI;
String[] projection = new String[]{
CalendarContract.Calendars._ID,
CalendarContract.Calendars.ACCOUNT_NAME,
CalendarContract.Calendars.ACCOUNT_TYPE,
CalendarContract.Calendars.NAME,
CalendarContract.Calendars.CALENDAR_DISPLAY_NAME,
CalendarContract.Calendars.CALENDAR_COLOR,
CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL,
CalendarContract.Calendars.OWNER_ACCOUNT,
CalendarContract.Calendars.VISIBLE,
CalendarContract.Calendars.SYNC_EVENTS
};
String selection = CalendarContract.Calendars.NAME + "=?";
String[] selectionArgs = new String[]{CALENDAR_NAME};
Cursor cursor = contentResolver.query(calendarUri, projection, selection, selectionArgs, null);
if (cursor != null && cursor.moveToFirst()) {
do {
long id = cursor.getLong(cursor.getColumnIndex(CalendarContract.Calendars._ID));
String accountName = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.ACCOUNT_NAME));
String accountType = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.ACCOUNT_TYPE));
String name = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.NAME));
String displayName = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_DISPLAY_NAME));
int color = cursor.getInt(cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_COLOR));
int accessLevel = cursor.getInt(cursor.getColumnIndex(CalendarContract.Calendars.CALENDAR_ACCESS_LEVEL));
String ownerAccount = cursor.getString(cursor.getColumnIndex(CalendarContract.Calendars.OWNER_ACCOUNT));
int visible = cursor.getInt(cursor.getColumnIndex(CalendarContract.Calendars.VISIBLE));
int syncEvents = cursor.getInt(cursor.getColumnIndex(CalendarContract.Calendars.SYNC_EVENTS));
// 輸出日歷信息
System.out.println("ID: " + id);
System.out.println("Account Name: " + accountName);
System.out.println("Account Type: " + accountType);
System.out.println("Name: " + name);
System.out.println("Display Name: " + displayName);
System.out.println("Color: " + color);
System.out.println("Access Level: " + accessLevel);
System.out.println("Owner Account: " + ownerAccount);
System.out.println("Visible: " + visible);
System.out.println("Sync Events: " + syncEvents);
} while (cursor.moveToNext());
cursor.close();
}
}
}

在上面的示例中,我們首先定義了一個常量CALENDAR_NAME,它表示要創建和查詢的日歷的

0
平和县| 临颍县| 东台市| 枣阳市| 图片| 柞水县| 神池县| 台东市| 库车县| 罗田县| 江油市| 文水县| 廊坊市| 甘谷县| 闽侯县| 旅游| 塔河县| 革吉县| 抚顺县| 锦屏县| 中宁县| 芮城县| 金坛市| 建宁县| 峡江县| 颍上县| 濉溪县| 昌邑市| 耒阳市| 鹿邑县| 济阳县| 宁国市| 丰原市| 姚安县| 常宁市| 扎兰屯市| 芜湖县| 平凉市| 上杭县| 同德县| 祁东县|