如何在从Android Market下载和安装应用程序后启用自动快捷方式创建?

wik*_*hen 13 android google-play

我注意到Android Market上的某些应用程序在下载并安装到您的设备后会自动在桌面上创建快捷方式,而有些则不会.我该如何实现这种行为?

Dan*_*n S 15

将意图发送给启动器.使用EXTRA_SHORTCUT_NAME和EXTRA_SHORTCUT_INTENT广播INSTALL_SHORTCUT意图.额外的EXTRA_SHORTCUT_DUPLICATE可用于帮助管理正在进行的重复快捷方式.该信息可在找到的launcher2项目AOSP库.

请注意,有些用户可能不喜欢未经许可创建快捷方式.

这是一些伪代码:

Intent installIntent = new Intent(InstallShortcutReceiver.ACTION_CREATE_SHORTCUT);
Intent myAppIntent = new Intent(Context.getPackageContext(), MyActivity.class);
installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Context.getString(R.string.app_name));
installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, myAppIntent);
installIntent.putExtra(Intent.SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));
Context.sendBroadcast(installIntent);
Run Code Online (Sandbox Code Playgroud)

Intent类中还有一些信息以及另一个Intent 操作.


wik*_*hen 5

事实证明,当您下载应用时,Android Market会自动安装桌面快捷方式.我在使用Honeycomb(3.0+)目标应用的Android 3.1平板电脑上注意到这种默认行为.对于在以前的Android版本上运行的应用程序来说,这似乎不是标准惯例,在首次下载/启动应用程序时需要明确的用户输入/权限.