【学以致用】android功能实现7---android8.0 Launcher获取快捷方式源码分析(3)

本文详细分析了在Android 8.0中如何实现 Launcher 获取并创建快捷方式的过程,包括获取快捷方式信息、添加到数据库、保存 ShortcutInfo、设置图标以及点击快捷方式启动应用的流程。主要涉及 LauncherAppState、DeepShortcutManager 和 ShortcutInfo 的使用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

获取完快捷方式的信息之后,便是如何具体的将快捷方式的名字,图标和打开方式放置到桌面上。

 

最后一步addAndBindAddedWorkspaceItems(
                new LazyShortcutsProvider(context.getApplicationContext(), items));

 

先将获取的LazyShortcutsProvider,是将PendingInstallShortcutInfo放在LazyShortcutsProvider,然后传入addAndBindAddedWorkspaceItems

 

这里实际是做了一个任务,工作包括获取 workspaceApps = mAppsProvider.get()

分配该快捷方式的位置Pair<Long, int[]> coords = findSpaceForItem(app, dataModel, workspaceScreens, addedWorkspaceScreensFinal, item.spanX, item.spanY); 

以及代码里面注释提到的这两句。

// Add the shortcut to the db
 // Save the ShortcutInfo for binding in the workspace

public void execute(LauncherAppState app, BgDataModel dataModel, AllAppsList apps) {
    List<ItemInfo> workspaceApps = mAppsProvider.get();
    if (workspaceApps.isEmpty()) {
        return;
    }
    Context context = app.getContext();

    final ArrayList<ItemInfo> addedItemsFinal = new ArrayList<>();
    final ArrayList<Long> addedWorkspaceScreensFinal = new ArrayList<>();

    // Get the list of workspace screens.  We need to append to this list and
    // can not use sBgWorkspaceScreens because loadWorkspace() may not have been
    // called.
    ArrayList<Long> workspaceScreens = LauncherModel.loadWorkspaceScreensDb(context);
    synchronized(dataModel) {
        for (ItemInfo item : workspaceApps) {
            if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_APPLICATION ||
                    it

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值