gpt4 book ai didi

java - 在主屏幕中创建快捷方式

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

我想为用户提供添加主屏幕快捷方式以启动应用程序的选项(在首次启动时提示他)。

我看到,例如 Whatsapp 会自动创建该图标

我该怎么做?该应用程序是否需要额外的权限?谢谢

我正在尝试(但不起作用)

    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

// Shortcut name
shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "MyApp");
shortcut.putExtra("duplicate", false); // Just create once

// Setup current activity shoud be shortcut object
ComponentName comp = new ComponentName(this.getPackageName(), "."+this.getLocalClassName());
shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));

// Set shortcut icon
ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher);
shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);

sendBroadcast(shortcut);

最佳答案

您是否在 list 文件中设置了 Activity Intent ?在这里阅读:

Android create shortcuts on the home screen

关于java - 在主屏幕中创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8546885/

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