我想创建快捷方式

侠子06

我在打开应用程序时创建快捷方式,但问题是创建快捷方式总是会在我打开应用程序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);
}
Amokrane Chentir

在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);

更多信息在这里

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

我想创建快捷方式

来自分类Dev

创建快捷方式

来自分类Dev

使用数据创建快捷方式

来自分类Dev

如何创建快捷方式

来自分类Dev

如何创建快捷方式

来自分类Dev

使用数据创建快捷方式

来自分类Dev

在 Okular 中创建快捷方式

来自分类Dev

在Windows中以编程方式创建快捷方式

来自分类Dev

为scp linux命令创建快捷方式命令

来自分类Dev

为导航功能创建快捷方式

来自分类Dev

izpack:在Windows 7上创建快捷方式

来自分类Dev

为git命令创建快捷方式

来自分类Dev

vbscript从未知目录的.exe创建快捷方式

来自分类Dev

如何为命令创建快捷方式?

来自分类Dev

使用Windows API创建快捷方式.lnk

来自分类Dev

无法在C#中创建快捷方式

来自分类Dev

如何为命令创建快捷方式?

来自分类Dev

为导航功能创建快捷方式

来自分类Dev

使用Shell脚本创建快捷方式

来自分类Dev

在Android中在家中创建快捷方式的吐司

来自分类Dev

在主屏幕中为APK创建快捷方式

来自分类Dev

为scp linux命令创建快捷方式命令

来自分类Dev

从命令行创建快捷方式

来自分类Dev

为更改其目录的程序创建快捷方式

来自分类Dev

在Ubuntu中创建快捷方式或脚本

来自分类Dev

使用应用程序路径创建快捷方式

来自分类Dev

在Bat或VBS中创建快捷方式

来自分类Dev

如何为Eclipse创建快捷方式

来自分类Dev

如何为sh文件创建快捷方式?