gpt4 book ai didi

android - 我要创建快捷方式

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

我在打开应用程序时创建了快捷方式,但问题是如果我打开应用程序 20 次然后创建 20 个快捷方式,创建的快捷方式总是会打开应用程序

我只需要在第一次打开时创建一个快捷方式,而不是更多

protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

ShortcutIcon();

}




private void ShortcutIcon(){

Intent shortcutIntent = new Intent(getApplicationContext(), Main.class);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

Intent addIntent = new Intent();
addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Whatsapp Imagenes");
addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.icono));
addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(addIntent);
}

最佳答案

在 JB 之前的 android 版本上,你可以试试这个:

addIntent.putExtra("duplicate", false);

否则,您可以卸载并重新安装快捷方式:

intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);

intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);

更多信息 here .

关于android - 我要创建快捷方式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20864785/

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