Example usage for android.content Intent EXTRA_SHORTCUT_INTENT

List of usage examples for android.content Intent EXTRA_SHORTCUT_INTENT

Introduction

In this page you can find the example usage for android.content Intent EXTRA_SHORTCUT_INTENT.

Prototype

String EXTRA_SHORTCUT_INTENT

To view the source code for android.content Intent EXTRA_SHORTCUT_INTENT.

Click Source Link

Document

The name of the extra used to define the Intent of a shortcut.

Usage

From source file:Main.java

public static void removeShortCut(Context context, String appName, Intent tagIntent) {
    Intent intent = new Intent("com.android.launcher.action.UNINSTALL_SHORTCUT");
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, tagIntent);
    context.sendBroadcast(intent);/*ww w .  jav  a  2  s . c  om*/
}

From source file:Main.java

public static String getAppName(Context context, Intent appIntent) {

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_NAME)) {
        return appIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    }//from   w  w w.ja v a2s  . c  o m

    if (appIntent.hasExtra(Intent.EXTRA_SHORTCUT_INTENT)) {
        appIntent = appIntent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    }
    ComponentName componentName = appIntent.getComponent();

    PackageManager pm = context.getPackageManager();

    ApplicationInfo appInfo = null;
    ActivityInfo activityInfo = null;
    try {
        appInfo = pm.getApplicationInfo(componentName.getPackageName(), 0);
    } catch (PackageManager.NameNotFoundException e) {
        appInfo = null;
    }
    try {
        activityInfo = pm.getActivityInfo(componentName, 0);
    } catch (PackageManager.NameNotFoundException e) {
        e.printStackTrace();
    }
    if (appInfo == null) {
        return null;
    } else {
        CharSequence appName = pm.getApplicationLabel(appInfo);
        CharSequence activityName = null;

        if (activityInfo != null) {
            activityName = activityInfo.loadLabel(pm);
        }

        if (activityName != null) {
            return activityName.toString();
        }

        if (appName != null) {
            appName.toString();
        }

        return null;
    }
}

From source file:Main.java

public static void installLaunchShortCut(Context context, Intent intent, String shortCutName, Bitmap icon,
        boolean duplicate) {
    Intent shortCutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    shortCutIntent.putExtra("duplicate", duplicate);
    intent.setAction(Intent.ACTION_MAIN);
    shortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    context.sendBroadcast(shortCutIntent);
}

From source file:Main.java

/**
 * Creates an intent that will add a shortcut to the home screen.
 * @param title Title of the shortcut./*from  w ww  .  java  2 s  .co  m*/
 * @param icon Image that represents the shortcut.
 * @param shortcutIntent Intent to fire when the shortcut is activated.
 * @return Intent for the shortcut.
 */
public static Intent createAddToHomeIntent(String title, Bitmap icon, Intent shortcutIntent) {
    Intent i = new Intent(INSTALL_SHORTCUT);
    i.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    i.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    i.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    return i;
}

From source file:Main.java

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 ww . ja v  a 2 s  . c  om
}

From source file:Main.java

public static void createDeskShortCut(Context cxt, String shortCutName, int icon, Class<?> cls) {
    Intent shortcutIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutIntent.putExtra("duplicate", false);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    Parcelable ico = Intent.ShortcutIconResource.fromContext(cxt.getApplicationContext(), icon);
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, ico);
    Intent intent = new Intent(cxt, cls);
    intent.setAction("android.intent.action.MAIN");
    intent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    cxt.sendBroadcast(shortcutIntent);//from   w w  w.  j av  a 2  s. c  o  m
}

From source file:MainActivity.java

public void createShortcut(View view) {
    Intent shortcutIntent = new Intent(this, MainActivity.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);
    Intent installIntent = new Intent();
    installIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    installIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    installIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher));
    installIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(installIntent);/*from www .  j  a  v a2s .c om*/
}

From source file:at.tomtasche.reader.ui.activity.ShortcutActivity.java

@Override
public DocumentLoader loadUri(Uri uri) {
    ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);

    Intent intent = new Intent();

    Intent launchIntent = new Intent(this, MainActivity.class);
    launchIntent.setAction(Intent.ACTION_VIEW);
    launchIntent.setData(uri);//  w  w w.ja v  a2s. c om

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, uri.getLastPathSegment());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);

    finish();

    return null;
}

From source file:com.github.yuukis.businessmap.app.IncomingShortcutActivity.java

private void createShortcut(ContactsGroup group) {
    if (group == null) {
        setResult(RESULT_CANCELED, null);
        return;/*  w  ww .j a  v a 2 s. com*/
    }
    long groupId = group.getId();
    String shortcutTitle = group.getTitle();
    if (shortcutTitle.isEmpty()) {
        shortcutTitle = getString(R.string.app_name);
    }

    Intent shortcutIntent = new Intent(getApplicationContext(), MainActivity.class);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    shortcutIntent.putExtra(MainActivity.KEY_CONTACTS_GROUP_ID, groupId);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getApplicationContext(),
            R.drawable.ic_launcher);
    // ????????
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    // ??????????
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutTitle);

    setResult(RESULT_OK, intent);
}

From source file:cm.aptoide.ptdev.preferences.ManagerPreferences.java

public void createLauncherShortcut(Context context, int drawable) {

    //removeLauncherShortcut(context);

    Intent shortcutIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    Log.d("Aptoide-Shortcut", "Creating Intent");
    final Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, Aptoide.getConfiguration().getMarketName());

    Parcelable iconResource;/*from   ww w  . j a  v a2 s.c  o m*/

    iconResource = Intent.ShortcutIconResource.fromContext(context, drawable);

    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    intent.putExtra("duplicate", false);
    intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");

    context.sendBroadcast(intent);

}