2014. 12. 22. 11:15
public static void addShortcut(Context context)
{
if(!pref.getBoolean("addshotcut",false))
{
editor.putBoolean("addshotcut", true);
editor.commit();

Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
shortcutIntent.setClassName(context, context.getClass().getName());
shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
| Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);

Intent intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
context.getResources().getString(R.string.app_name)); 
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
Intent.ShortcutIconResource.fromContext(context,
R.drawable.ic_launcher));
intent.putExtra("duplicate", false);
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

context.sendBroadcast(intent);
}
}



Manifest에


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


추가

Posted by newkie