温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》
  • 首页 > 
  • 教程 > 
  • 开发技术 > 
  • Android数据转移中怎么用Launcher导出数据库给另一台机器加载

Android数据转移中怎么用Launcher导出数据库给另一台机器加载

发布时间:2021-11-04 10:38:01 来源:亿速云 阅读:153 作者:iii 栏目:开发技术

本篇内容主要讲解“Android数据转移中怎么用Launcher导出数据库给另一台机器加载”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Android数据转移中怎么用Launcher导出数据库给另一台机器加载”吧!

功能描述

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导出数据库给另一台机器加载”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI