gpt4 book ai didi

android - 如何在安装应用程序时将应用程序的快捷方式添加到主屏幕?

转载 作者:IT老高 更新时间:2023-10-28 21:54:04 26 4
gpt4 key购买 nike

我想在安装我的应用程序后立即在主屏幕上创建我的应用程序的快捷方式/启动器图标(甚至在我启动它之前)。那可能吗?我该怎么做?

最佳答案

从 ICS 开始,您可以这样做:

public void createShortCut(){
Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
shortcutintent.putExtra("duplicate", false);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcutname));
Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(getApplicationContext(), EnterActivity.class));
sendBroadcast(shortcutintent);
}

另请参阅启动器源代码:this link

编辑:如果有人会错过阅读评论,请添加以下行。

这需要“com.android.launcher.permission.INSTALL_SHORTCUT”权限

关于android - 如何在安装应用程序时将应用程序的快捷方式添加到主屏幕?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18327173/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com