繁体   English   中英

安装Android应用时如何将小部件添加为图标

[英]How to add a widget as an icon when install android app

我在Play商店上看到了一些应用程序,在安装这些应用程序时,它们会自动添加一个图标(如果我们触摸过或出于其他任何原因,则可以显示其新应用程序)。 怎么做。

只需将其添加到您的清单中:

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

并使用此代码:

Intent shortcutIntent = new Intent();
Intent i = new Intent();
i.setClassName(getPackageName(), getPackageName());
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i);
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getPackageName());
shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(getApplicationContext(),
                        R.drawable.icon));
shortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        this.sendBroadcast(shortcutIntent);

您可以将图标更改为应用程序图标,并更改应用程序名称

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM