create Shortcut - Android android.content

Android examples for android.content:Intent

Description

create Shortcut

Demo Code

import android.content.Context;
import android.content.Intent;

public class Main {

  public static void createShortcut(Context ctx, String shortCutName, int iconId, Intent presentIntent) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(ctx, iconId));
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent);
    ctx.sendBroadcast(shortcutIntent);// w  w  w.j  av  a  2  s. co m
  }

}

Related Tutorials