create Short Cut via Intent - Android Intent

Android examples for Intent:Short cut

Description

create Short Cut via Intent

Demo Code

import android.R;
import android.content.Context;
import android.content.Intent;
import android.os.Parcelable;

public class Main {
  public static void createShortCut(Context context, String action) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra("duplicate", false);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, "QK-LINX");

    Parcelable icon = Intent.ShortcutIconResource.fromContext(context,
        R.drawable.ic_launcher);//from w  ww  .  j  a  v a  2 s .  c om
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    Intent intent = new Intent();
    intent.setAction(action);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    context.sendBroadcast(shortcut);
  }
}

Related Tutorials