0
我在Play商店中看到一些应用程序,安装这些应用程序时会自动添加图标(如果我们触及或其他原因显示其新应用程序)。怎么做。如何在安装Android应用程序时将图标添加为图标
我在Play商店中看到一些应用程序,安装这些应用程序时会自动添加图标(如果我们触及或其他原因显示其新应用程序)。怎么做。如何在安装Android应用程序时将图标添加为图标
只是添加到您的清单:
<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);
您可以将图标更改为您的应用程序图标,更改应用程序的名称
感谢你的回复。我尝试使用此代码到我的应用程序,但它不起作用。我添加onCreate()。 – ThuongNM 2012-03-24 19:52:06
我认为你不会将这个权限添加到你的清单中,我正在检查我的代码,然后在这里发送它,将此添加到清单: –
AliSh
2012-03-24 20:50:44
我加了。你能寄给我样品项目吗?谢谢 – ThuongNM 2012-03-25 09:59:07