安卓系统的日历里面有个新建事件的功能、只有在创建了账户的情况下才能创建事件、4.1.2系统版本里面、我想在日历Calendar的入口代码处添加一个本地默认账户、但是怎么添加都不行、不知道为什么、求牛人指教、
2.3.5的代码里面添加是可以的、但是到了4.1.2的里面、我把字段名都改好了、但还是不行、
static public void createCalendar(Context context) {
Bundle options = new Bundle();
options.putString(LocalCalendarAccountService.OPTIONS_ACCOUNT_NAME, ACCOUNT_NAME);
options.putString(LocalCalendarAccountService.OPTIONS_ACCOUNT_TYPE, ACCOUNT_TYPE);
AccountManager.get(context).addAccount(ACCOUNT_TYPE, null, null, options, null, null, null);
ContentValues cv = new ContentValues();
cv.put(Calendars.DISPLAY_NAME, ACCOUNT_NAME);
cv.put(Calendars._SYNC_ACCOUNT, ACCOUNT_NAME);
cv.put(Calendars._SYNC_ACCOUNT_TYPE, ACCOUNT_TYPE);
cv.put(Calendars.SYNC_EVENTS, 1);
cv.put(Calendars.SELECTED, 1);
cv.put(Calendars.HIDDEN, 0);
cv.put(Calendars.ORGANIZER_CAN_RESPOND, 0);
cv.put(Calendars.COLOR, 0xFF000000 | 0x71aea7);
cv.put(Calendars.TIMEZONE, Time.getCurrentTimezone());
cv.put(Calendars.ACCESS_LEVEL, Calendars.OWNER_ACCESS);
cv.put(Calendars.OWNER_ACCOUNT, ACCOUNT_NAME);
context.getContentResolver().insert(Calendars.CONTENT_URI, cv);
}
求4.1.2里面该如何创建、在线等、
------解决思路----------------------
在packages\providers\CalendarProvider\src\com\android\providers\calendar\CalendarDatabaseHelper.java增加updateOrInsert方法即可
private void bootstrapDB(SQLiteDatabase db) {
Log.i(TAG, "Bootstrapping database");
mSyncState.createDatabase(db);
createColorsTable(db);
createCalendarsTable(db);
//begin : added by xxx for calendar demand
updateOrInsert(db,"Calendars");
//end : added by xxx for calendar demand
createEventsTable(db);
......
//begin : added by xxx for calendar demand
private void updateOrInsert(SQLiteDatabase db, String table){
// check this value exsist or not.
String account_name = "Phone";
String account_type = "com.android.huawei.phone";
String calendar_displayName = "Phone";
Integer calendar_color = -12011288;
Integer calendar_access_level = 700;
Integer sync_events = 1;
String calendar_timeZone = "Asia/shanghai";
String ownerAccount = "Phone";
String[] columns = new String[]{"account_name","account_type"," calendar_displayName"};
String selection = " account_name=? and account_type=? and calendar_displayName=? ";
String[] selectionArgs = new String[]{account_name,account_type,calendar_displayName};
boolean alreadyExisted = false;
// Cursor cursor = db.query(table, columns, selection, selectionArgs, null, null, null);
Cursor cursor = db.query(table, columns, selection, selectionArgs, null, null, null);
alreadyExisted = (null != cursor) && (cursor.getCount() > 0);
/*