Tuesday, April 21, 2015

Android 바탕화면 바로가기 만들기

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

private void addShortcut(Context context) {
   Intent shortcutIntent = new Intent();
   shortcutIntent.setAction(Intent.ACTION_MAIN);
   shortcutIntent.addCategory(Intent.CATEGORY_LAUNCHER);
   shortcutIntent.setClassName(context, getClass().getName());
   shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
 
   Parcelable iconResource = Intent.ShortcutIconResource.fromContext( this,  R.drawable.ic_launcher);
 
   Intent intent = new Intent();
   intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
   intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getResources().getString(R.string.app_name));
   intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,iconResource);
   intent.putExtra("duplicate", false);
   intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");      
   sendBroadcast(intent);  
 }

No comments:

Post a Comment