gpt4 book ai didi

java - 如何在安装时在 Android 手机的主屏幕上创建应用程序快捷方式

转载 作者:行者123 更新时间:2023-11-29 07:06:25 25 4
gpt4 key购买 nike

我已经创建了一个 android 应用程序,它运行良好但现在我想添加一个功能,在安装时应用程序应该在主屏幕上创建一个快捷方式

请推荐我不想要完整的代码工作简单的步骤就足够了

最佳答案

首先声明您的应用程序正在使用 AndroidManifest.xml 中的 INSTALL_SHORTCUT 权限。

    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />



Intent shortcutIntent = new Intent();
shortcutIntent.setClassName("com.example.androidapp", "SampleIntent");
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra("someParameter", "HelloWorld");

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Shortcut Name");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, R.drawable.icon));

addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
context.sendBroadcast(addIntent);

关于java - 如何在安装时在 Android 手机的主屏幕上创建应用程序快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19240194/

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