Android Calendar添加本地账户
2016-10-26 23:00
1296 查看
在Android原生代码中,日历App如要添加活动,需要先添加账户,不方便用户的使用。反编译某某系统的
主要修改了
关于谷歌的账户和同步,有很多需要学习的,与其费劲的自己写日历、联系人的同步,不如学习和使用谷歌提供的账户和SyncAdapter更方便。
CalendarProvider.apk,从中提取了添加本地账户的代码,在此共享。
主要修改了
/packages/providers/CalendarProvider/下的
CalendarDatabaseHelper.java文件,其中包括了日历数据库的创建等操作。
// 系统创建日历数据库表结构的函数 private void createCalendarsTable(SQLiteDatabase db) { db.execSQL(/* 创建 Tables.CALENDARS 表 */); // 添加本地日历账户 insertLocalAccount(db);/* 创建表成功后,添加本地账户到数据库 */ // 创建活动被删除时的触发器 // Trigger to remove a calendar's events when we delete the calendar db.execSQL("CREATE TRIGGER calendar_cleanup DELETE ON " + Tables.CALENDARS + " " + "BEGIN " + CALENDAR_CLEANUP_TRIGGER_SQL + "END"); } private void insertLocalAccount(SQLiteDatabase db) { // 添加本地日历账户 insertAccount(db, "account_name_local", "LOCAL", mContext.getResources().getString(R.string.calendar_displayname_local), 700, mContext.getResources().getString(R.string.owner_account_local), mContext.getResources().getColor(R.color.calendar_local_color), 5); // 添加生日提醒账户 这个需要联系人App作同步修改,不需要的可以不加入 insertAccount(db, "account_name_local", "LOCAL", mContext.getResources().getString(R.string.calendar_displayname_birthday), 300, mContext.getResources().getString(R.string.owner_account_local), mContext.getResources().getColor(R.color.calendar_local_birthday), 0); } private void insertAccount(SQLiteDatabase db, String accountName, String accountType, String calendarDisplayName, int calendarAccessLevel, String ownerAccount, int calendarColor, int maxReminders) { ContentValues localContentValues = new ContentValues(); localContentValues.put("account_name", accountName);// 账户名称 localContentValues.put("account_type", accountType);// 账户类型 localContentValues.put("calendar_displayName", calendarDisplayName);// 显示的账户名称 localContentValues.put("calendar_access_level", Integer.valueOf(calendarAccessLevel));// 访问级别 localContentValues.put("ownerAccount", ownerAccount);// 账户拥有者 localContentValues.put("calendar_color", Integer.valueOf(calendarColor));// 账户区别颜色 localContentValues.put("sync_events", Integer.valueOf(1));// 是否同步 localContentValues.put("maxReminders", Integer.valueOf(maxReminders));// 最多设置的提醒器数量 db.insert("Calendars", null, localContentValues); }
关于谷歌的账户和同步,有很多需要学习的,与其费劲的自己写日历、联系人的同步,不如学习和使用谷歌提供的账户和SyncAdapter更方便。
相关文章推荐
- android 4.0 Calendar 添加默认账户
- 【安卓】[Android]添加google账户 - 您的用户名和密码不匹配,请重试
- ArcGIS for Android 之本地离线地图添加(LocalTitledLayer)
- Android 添加Calendar 事件。问题
- [Android] 通过GridView仿微信动态添加本地图片示例代码
- Android中播放本地SD卡中歌曲需要的添加的权限
- android TextView 添加多连接 访问本地
- 安卓android添加文本到图片并保持到本地
- android添加图片到本地,无法即使刷新的解决方法
- Android中播放本地SD卡中歌曲需要的添加的权限
- Android 实现添加本地数组在Res/values下的xml文件
- Android新浪微博客户端(二)——添加多个账户及认证
- Win10 启用或添加本地账户的方法
- Android防止手动添加的本地库文件被NDK工具清理掉
- [Android] 通过GridView仿微信动态添加本地图片
- Android 添加数据到本地Excel表中
- Android 4.2(JB2)加入多账户后input&language以及Calendar的变化总结
- android添加图片到本地,无法即使刷新的解决方法
- android 日历本地账户
- Android如何在账户设置中添加App的账户