添加快捷方式

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

 

Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME,getString(R.string.app_name));

   shortcutIntent.putExtra("duplicate", false);

   Intent intent = new Intent();

   intent.setComponent(new ComponentName(getPackageName(), MainActivity.class.getName()));

   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

   shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));

   sendBroadcast(shortcutIntent);

posted @ 2011-07-01 16:01  Gang.Wang  阅读(543)  评论(0编辑  收藏  举报