为了获取快捷方式,packageName和ID是Laucnher传递快捷方式的主要信息,而其载体则是Laucnher自己通过makeIntent创建的intent,详见上章最后。和7.0不同,快捷方式的信息有一半是保存在系统里,通过数据库是查阅不到快捷方式的实际地址。
下面看看快捷方式的信息是如何在Laucnher中转化成快捷方式图标的。
创建好intent后,来自intent的信息则放入了PendingInstallShortcutInfo中,随后将其放入创建列表。
public static void queueShortcut(ShortcutInfoCompat info, Context context) {
queuePendingShortcutInfo(new PendingInstallShortcutInfo(info, context), context);
}
创建快捷方式,这里分为两步走,1:addToInstallQueue 2:flushInstallQueue 剩下的是判断是否创建快捷方式的流程,如果创建(也就是本流程的主要流程)。则走1、2两步
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包,放置到sharedPrefs的APPS_PENDING_INSTALL中。
本方法关注两个参数,一个是encoded 的内容,一个是关键词APPS_PENDING_INSTALL.
private static void addToInstallQueue(
SharedPreferences sharedPrefs, PendingInstallShortcutInfo info) {
&nbs