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

本文详细解析了Android 8.0 Launcher如何处理快捷方式,包括如何将intent信息转化为PendingInstallShortcutInfo,放入安装队列,并通过DeepShortcutManager查询和获取快捷方式详情,最终创建并绑定到工作区。

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

为了获取快捷方式,packageNameIDLaucnher传递快捷方式的主要信息,而其载体则是Laucnher自己通过makeIntent创建的intent,详见上章最后。和7.0不同,快捷方式的信息有一半是保存在系统里,通过数据库是查阅不到快捷方式的实际地址。

下面看看快捷方式的信息是如何在Laucnher中转化成快捷方式图标的。

创建好intent后,来自intent的信息则放入了PendingInstallShortcutInfo中,随后将其放入创建列表。

 

public static void queueShortcut(ShortcutInfoCompat info, Context context) {
    queuePendingShortcutInfo(new PendingInstallShortcutInfo(info, context), context);
}

 

创建快捷方式,这里分为两步走,1addToInstallQueue 2flushInstallQueue 剩下的是判断是否创建快捷方式的流程,如果创建(也就是本流程的主要流程)。则走12两步

 

private static void queuePendingShortcutInfo(PendingInstallShortcutInfo info, Context context) {
    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState app = LauncherAppState.getInstance(context);
    boolean launcherNotLoaded = app.getModel().getCallback() == null;

    addToInstallQueue(Utilities.getPrefs(context), info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

 

第一步addToInstallQueue的工作是:将参数形成jSon包,放置到sharedPrefsAPPS_PENDING_INSTALL中。

 

本方法关注两个参数,一个是encoded 的内容,一个是关键词APPS_PENDING_INSTALL.

 

private static void addToInstallQueue(
        SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) {
 &nbs

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值