2012-03-24 68 views

回答

3

只是添加到您的清单:

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

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

+0

感谢你的回复。我尝试使用此代码到我的应用程序,但它不起作用。我添加onCreate()。 – ThuongNM 2012-03-24 19:52:06

+0

我认为你不会将这个权限添加到你的清单中,我正在检查我的代码,然后在这里发送它,将此添加到清单: AliSh 2012-03-24 20:50:44

+0

我加了。你能寄给我样品项目吗?谢谢 – ThuongNM 2012-03-25 09:59:07

相关问题