在android系统开发过程中。发现有些应用在安装后,在主菜单中第一次进入之后,此应用的icon会自动加载到待机页面上。 通过launcher3源码发现。 在AndroidManifest.xml中
<!-- Intent received used to install shortcuts from other applications --> <receiver android:name="com.android.launcher3.extension.MockInstallShortcutReceiver" android:permission="com.android.launcher.permission.INSTALL_SHORTCUT"> <intent-filter> <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" /> </intent-filter> </receiver>launcher3 静态注册了 com.android.launcher.action.INSTALL_SHORTCUT 广播。 有些应用,如微信等在第一次进入后,会想系统发上面的广播。 launcher3 在接收到此广播后会将此icon加载到待机页面。
public class InstallShortcutReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent data) { if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) { return; } PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context); if (info.launchIntent == null || info.label == null) { if (DBG) Log.e(TAG, "Invalid install shortcut intent"); return; } info = convertToLauncherActivityIfPossible(info); queuePendingShortcutInfo(info, context); } }