create Shortcut Intent - Android android.content

Android examples for android.content:Intent

Description

create Shortcut Intent

Demo Code

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

public class Main {

  public static void createShortcut(Context context, Intent intent, String title, int iconId) {
    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");

    Parcelable icon = Intent.ShortcutIconResource.fromContext(context, iconId);

    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    // shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON, R.drawable.beach);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);

    context.sendBroadcast(shortcut);//from  w w w.j a  v  a2 s. c  om
  }

}

Related Tutorials