溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

Android數(shù)據(jù)轉(zhuǎn)移中怎么用Launcher導(dǎo)出數(shù)據(jù)庫給另一臺機(jī)器加載

發(fā)布時間:2021-11-04 10:38:01 來源:億速云 閱讀:159 作者:iii 欄目:開發(fā)技術(shù)

本篇內(nèi)容主要講解“Android數(shù)據(jù)轉(zhuǎn)移中怎么用Launcher導(dǎo)出數(shù)據(jù)庫給另一臺機(jī)器加載”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強(qiáng)。下面就讓小編來帶大家學(xué)習(xí)“Android數(shù)據(jù)轉(zhuǎn)移中怎么用Launcher導(dǎo)出數(shù)據(jù)庫給另一臺機(jī)器加載”吧!

功能描述

1、導(dǎo)出當(dāng)前l(fā)auncher布局。
2、把布局文件拷貝到另一個機(jī)器。(模擬上傳下載服務(wù)器布局文件)
3、更新launcher布局。

需求分析

1、數(shù)據(jù)庫拷貝
2、導(dǎo)入數(shù)據(jù)庫
3、對桌面圖標(biāo)進(jìn)行分類:
app folder不需要修改,可以直接顯示;
widget、deepshortcut、1*1shortcut需要適配后才能顯示。

實現(xiàn)思路

1、導(dǎo)出launcher布局

只需要將launcher數(shù)據(jù)庫copy出去即可

2、導(dǎo)入數(shù)據(jù)庫

將數(shù)據(jù)庫文件copy到launcher data/data/包名/database/launcher.db
要注意的是,因為launcher在運(yùn)行過程中,替換數(shù)據(jù)庫文件會導(dǎo)致舊的數(shù)據(jù)庫對象DatabaseHelper無法操作新數(shù)據(jù)庫,如果不做處理,再次操作數(shù)據(jù)庫會有crash;需要重新初始化數(shù)據(jù)庫對象或者重啟launcher,在數(shù)據(jù)庫初始化之前完成copy動作。

3、適配桌面支持的圖標(biāo)類型

loadWorkspace中,從數(shù)據(jù)庫中加載信息:
3.1、app folder 不需要適配
3.2、widget:
widget適配,參考默認(rèn)配置布局中從xml讀取數(shù)據(jù)庫,加載widget流程。
widget默認(rèn)布局能配置上去,就能從數(shù)據(jù)庫中讀取包類名適配上去,只要保證他們走同一套流程即可。

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會在系統(tǒng)中注冊信息
//我們需要根據(jù)數(shù)據(jù)庫里的內(nèi)容,手動注冊到系統(tǒng),讓用戶重啟機(jī)器之后也能正常顯示
//1、查詢已經(jīng)注冊過的deepshortcut
List<ShortcutInfo> pinnedShortcuts = mShortcutManager.queryForPinnedShortcuts(null, user);
//根據(jù)數(shù)據(jù)庫key獲取pinnedShortcut,這里獲取不到,因為新手機(jī)沒有注冊過
} 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,長按圖標(biāo)會彈出的那種
//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、創(chuàng)建快捷方式屬性shortcutInfo
2、向底層申請創(chuàng)建快捷方式createShortcutResultIntent的Intent
3、固定快捷方式createWorkspaceItemFromPinItemRequest
1 2 步驟正常應(yīng)該在setting中進(jìn)行,3在launcher中。

全部放在launcher中執(zhí)行,無法達(dá)到預(yù)期效果
啟動快捷方式時,需要根據(jù)包名和id進(jìn)行啟動
如果是launcher的包名,只能打開設(shè)置主頁,無法跳到對應(yīng)的快捷方式界面。

1*1widget向底層綁定只是用pinShortcut是不行的,無法成功綁定。

//向系統(tǒng)注冊shortcut
//注冊失敗,會檢測包名和data中的包名
WorkspaceItemInfo infoinfo = LauncherAppsCompatVO.createWorkspaceItemFromPinItemRequest(
context, LauncherAppsCompatVO.getPinItemRequest(data), 0);
//再走上面的pinShortcut完成

到此,相信大家對“Android數(shù)據(jù)轉(zhuǎn)移中怎么用Launcher導(dǎo)出數(shù)據(jù)庫給另一臺機(jī)器加載”有了更深的了解,不妨來實際操作一番吧!這里是億速云網(wǎng)站,更多相關(guān)內(nèi)容可以進(jìn)入相關(guān)頻道進(jìn)行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI