功能描述

1、导出当前launcher布局。
2、把布局文件拷贝到另一个机器。(模拟上传下载服务器布局文件)
3、更新launcher布局。

需求分析

1、数据库拷贝
2、导入数据库
3、对桌面图标进行分类:
app folder不需要修改,可以直接显示;
widget、deepshortcut、1*1shortcut需要适配后才能显示。

实现思路

1、导出launcher布局

只需要将launcher数据库copy出去即可

2、导入数据库

将数据库文件copy到launcher data/data/包名/database/launcher.db
要注意的是,因为launcher在运行过程中,替换数据库文件会导致旧的数据库对象DatabaseHelper无法操作新数据库,如果不做处理,再次操作数据库会有crash;需要重新初始化数据库对象或者重启launcher,在数据库初始化之前完成copy动作。

3、适配桌面支持的图标类型

loadWorkspace中,从数据库中加载信息:
3.1、app folder 不需要适配
3.2、widget:
widget适配,参考默认配置布局中从xml读取数据库,加载widget流程。
widget默认布局能配置上去,就能从数据库中读取包类名适配上去,只要保证他们走同一套流程即可。

case LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET:
//widget需要更新widgetID和widget status
if (copySuccess){
	c.restoreFlag = LauncherAppWidgetInfo.FLAG_ID_NOT_VALID |
	LauncherAppWidgetInfo.FLAG_PROVIDER_NOT_READY |
	LauncherAppWidgetInfo.FLAG_DIRECT_CONFIG;
}

3.3、deep shortcut:

case LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT:
//deep shortcut会在系统中注册信息
//我们需要根据数据库里的内容,手动注册到系统,让用户重启机器之后也能正常显示
//1、查询已经注册过的deepshortcut
List<ShortcutInfo> pinnedShortcuts = mShortcutManager.queryForPinnedShortcuts(null, user);
//根据数据库key获取pinnedShortcut,这里获取不到,因为新手机没有注册过
} else if (c.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
	ShortcutKey key = ShortcutKey.fromIntent(intent, c.user);
	if (unlockedUsers.get(c.serialNumber)) {
	ShortcutInfo pinnedShortcut =shortcutKeyToPinnedShortcuts.get(key);
//
//快捷方式分二种,manifest里写的 CREATE_SHORTCUT,长按图标会弹出的那种
//LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
//LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
//LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED
//固定界面的deepShortCut可以正常显示,例如setting的BatterySaver,key为com.android.settings/manifest-shortcut-batterySaver#UserHandle{0}
//和
//widget列表里的1*1 未适配
if (pinnedShortcut == null && copySuccess){
    DeepShortcutManager sm = DeepShortcutManager.getInstance(context);
    List<ShortcutInfo> si = sm.queryForFullDetails(intent.getPackage(),null, c.user);
    shortcutKeyToPinnedShortcuts_copyDbFile.clear();
    Log.i(TAG,"key : "+key);
    for (ShortcutInfo shortcut : si) {
        ShortcutKey shortcutKey = ShortcutKey.fromInfo(shortcut);
        shortcutKeyToPinnedShortcuts_copyDbFile.put(shortcutKey,
                shortcut);
        Log.d(TAG,"shortcutKey : "+shortcutKey);
    }
    pinnedShortcut =
            shortcutKeyToPinnedShortcuts_copyDbFile.get(key);
    if (pinnedShortcut != null){
        copyDbFileNeedAddTo = true;
    }
}

//向底层绑定shortcut
com/tblenovo/launcher/model/BgDataModel.java
// Since this is a new item, pin the shortcut in the system server.
//ccsDeepShortCut need pinShortcut
if ((newItem || ccsDeepShortCUTItem) && count.value == 1) {
	DeepShortcutManager.getInstance(context).pinShortcut(pinnedShortcut);
}

3.4、11widget:
//widget列表里的1
1 未适配
长按添加setting中的1*1插件流程:
1、创建快捷方式属性shortcutInfo
2、向底层申请创建快捷方式createShortcutResultIntent的Intent
3、固定快捷方式createWorkspaceItemFromPinItemRequest
1 2 步骤正常应该在setting中进行,3在launcher中。

全部放在launcher中执行,无法达到预期效果
启动快捷方式时,需要根据包名和id进行启动
如果是launcher的包名,只能打开设置主页,无法跳到对应的快捷方式界面。

1*1widget向底层绑定只是用pinShortcut是不行的,无法成功绑定。

//向系统注册shortcut
//注册失败,会检测包名和data中的包名
WorkspaceItemInfo infoinfo = LauncherAppsCompatVO.createWorkspaceItemFromPinItemRequest(
context, LauncherAppsCompatVO.getPinItemRequest(data), 0);
//再走上面的pinShortcut完成

到此这篇关于Android数据转移之Launcher导出数据库给另一台机器加载的文章就介绍到这了,更多相关Android 数据转移内容请搜索悠悠之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持悠悠之家!

点赞(80)

评论列表共有 0 条评论

立即
投稿
返回
顶部