create Short Cut - Android android.content

Android examples for android.content:Intent

Description

create Short Cut

Demo Code

import android.app.Activity;
import android.content.Intent;
import android.os.Parcelable;

public class Main {

  public static void createShortCut(Activity activity, int iconResId, int appnameResId) {
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutintent.putExtra("duplicate", false);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, activity.getString(appnameResId));

    Parcelable icon = Intent.ShortcutIconResource.fromContext(activity.getApplicationContext(), iconResId);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
        new Intent(activity.getApplicationContext(), activity.getClass()));

    activity.sendBroadcast(shortcutintent);
  }//from w  w w.j  a  v  a  2  s  . co m

}

Related Tutorials