您的位置:首页 > 其它

关于launcher3 应用icon会自动添加到待机页面的问题

2017-04-14 15:44 387 查看
在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);
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: