亚洲激情专区-91九色丨porny丨老师-久久久久久久女国产乱让韩-国产精品午夜小视频观看

溫馨提示×

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
金塔县| 班戈县| 安宁市| 江城| 乐平市| 平定县| 中卫市| 任丘市| 衡水市| 塔城市| 雷波县| 嘉荫县| 丘北县| 佳木斯市| 湘乡市| 土默特左旗| 和田市| 临漳县| 会昌县| 仁化县| 葵青区| 额敏县| 和平区| 嘉善县| 滕州市| 亳州市| 竹溪县| 云霄县| 龙州县| 明溪县| 磐安县| 遵化市| 五家渠市| 治多县| 青海省| 昆明市| 丹阳市| 华宁县| 盘锦市| 永兴县| 广南县|