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:org.ulteo.ovd.MainWindow.java

private void addShortcut() {
    // check if user enter a login
    if (loginTxtField.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_miss_login, Toast.LENGTH_LONG).show();
        return;//w  ww . j  ava  2s . c  o m
    }
    // check if user enter a password
    if (passwdTxtField.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_miss_passwd, Toast.LENGTH_LONG).show();
        return;
    }
    // check if user enter an address
    String addr;
    if (Settings.getHideSm(this))
        addr = Settings.getIp(this);
    else
        addr = sessionmTxtField.getText().toString();
    if (addr.length() <= STRING_EMPTY) {
        Toast.makeText(MainWindow.this, R.string.error_ipaddr, Toast.LENGTH_LONG).show();
        return;
    }

    Intent shortcut = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, loginTxtField.getText().toString() + "@" + addr);
    shortcut.putExtra("duplicate", false); // Just create once
    String url = "ovd://" + loginTxtField.getText().toString() + ":" + passwdTxtField.getText().toString() + "@"
            + addr;
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(this, R.drawable.icon);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    sendBroadcast(shortcut);
}

From source file:org.nsdev.apps.superhappyhackmap.activities.MainActivity.java

private void addShortcut() {
    Intent shortcutIntent = new Intent(getApplicationContext(), ResetActivity.class);

    shortcutIntent.setAction(HackReceiver.ACTION_RESET_LAST_HACK);

    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Reset Sojourner");
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.mipmap.ic_reset_shortcut));

    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    getApplicationContext().sendBroadcast(addIntent);

    Toast.makeText(getApplicationContext(), "Sojourner reset shortcut created in launcher.", Toast.LENGTH_LONG)
            .show();/*  w w w . ja v  a2 s  .  co  m*/
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Allows to install a new icon for the application.
 *
 * This method need two additional permissions in the application:
 *
 * <code>//from ww w .  j av a 2s. co m
 *  <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 * </code>
 *
 * @param context       The application context.
 * @param appMain       The application main class
 * @param appName       The application name
 * @param appIcon       The bitmap of the application icon. Can be null. If null, the
 *                      appIconResId must be provided.
 * @param appIconResId  Specify this only if no bitmap is set in the call to this method.
 */
public static void application_shortcutAdd(Context context, Class appMain, String appName, Bitmap appIcon,
        int appIconResId, boolean removeCurrent) {

    // Intent launcher of the application
    Intent shortcutIntent = new Intent("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");
    shortcutIntent.setClass(context, appMain);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    //Intent to add the new application icon.
    //
    // Decorate the shortcut
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

    if (appIcon != null) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, appIcon);
    } else if (appIconResId != 0) {
        addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(context.getApplicationContext(), appIconResId));
    }

    // Inform launcher to create shortcut
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    context.sendBroadcast(addIntent);
}

From source file:org.openintents.notepad.NoteEditor.java

/**
 * Return intent data when invoked with//from w  w  w . j a va 2 s.  c  om
 * action=android.intent.action.CREATE_SHORTCUT
 */
private void createShortcut() {
    Intent intent = new Intent(Intent.ACTION_INSERT, Notes.CONTENT_URI, getApplicationContext(),
            NoteEditor.class);

    Intent result = new Intent();
    result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher_notepad));
    result.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.new_note));

    setResult(RESULT_OK, result);

    finish();
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Deletes a application desktop shortcut icon.
 *
 * This method need two additional permissions in the application:
 *
 * <code>//from   w w  w . j ava2s.c om
 *  <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
 * </code>
 *
 * @param context   The application context.
 * @param appClass  Shortcut's  activity class.
 * @param appName   The shortcut's name
 */
public static void application_shortcutRemove_method1(Context context, Class appClass, String appName) {
    Intent shortcutIntent = new Intent(context, appClass);
    shortcutIntent.setAction(Intent.ACTION_MAIN);

    Intent delIntent = new Intent();
    delIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    delIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);

    // Inform launcher to remove shortcut
    delIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(delIntent);
}

From source file:com.markupartist.sthlmtraveling.PlannerFragment.java

/**
 * Setup a search short cut./*from   ww w. j  av a2s  . c om*/
 * 
 * @param startPoint
 *            the start point
 * @param endPoint
 *            the end point
 */
protected void onCreateShortCut(Site startPoint, Site endPoint, String name) {
    Uri routesUri = RoutesActivity.createRoutesUri(startPoint, endPoint, null, true);
    Intent shortcutIntent = new Intent(Intent.ACTION_VIEW, routesUri, getActivity(), RoutesActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    // Then, set up the container intent (the response to the caller)
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(getActivity(), R.drawable.shortcut);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Now, return the result to the launcher
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();
}

From source file:com.android.purenexussettings.TinkerActivity.java

@Override
protected void onActivityResult(int paramRequest, int paramResult, Intent paramData) {
    super.onActivityResult(paramRequest, paramResult, paramData);
    if (paramResult != -1 || paramData == null) {
        return;/*from  w ww.  ja v  a 2  s.  c  o  m*/
    }
    switch (paramRequest) {
    case REQUEST_CREATE_SHORTCUT:
        Intent localIntent = paramData.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        localIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, paramData.getStringExtra(Intent.EXTRA_SHORTCUT_NAME));

        String keystring = localIntent.toUri(0).replaceAll("com.android.contacts.action.QUICK_CONTACT",
                Intent.ACTION_VIEW);

        Settings.Global.putString(getContentResolver(), TinkerActivity.mPrefKey, keystring);
        onBackPressed();

        return;
    default:
    }
}

From source file:es.javocsoft.android.lib.toolbox.ToolBox.java

/**
 * Deletes a application desktop shortcut icon.
 *
 * Note:/*from  ww  w .  ja v a2 s . c o m*/
 *  Manual way.
 *
 *  This method need two additional permissions in the application:
 *
 * <code>
 *  <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
 * </code>
 *
 * @param context   The application context.
 * @param appClass  Shortcut's  activity class.
 */
public static void application_shortcutRemove_method2(Context context, Class appClass, String appName) {
    Intent intent = new Intent();
    String oldShortcutUri = "#Intent;action=android.intent.action.MAIN;category=android.intent.category.LAUNCHER;launchFlags=0x10200000;package="
            + appClass.getPackage().getName() + ";component=" + appClass.getPackage().getName() + "/."
            + appClass.getSimpleName() + ";end";
    try {
        Intent altShortcutIntent = Intent.parseUri(oldShortcutUri, 0);
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, altShortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, appName);
        //intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    } catch (URISyntaxException e) {
    }
    intent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    context.sendBroadcast(intent);
}

From source file:com.xabber.android.ui.activity.ContactList.java

private void createShortcut(AbstractContact abstractContact) {
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
            ChatViewer.createShortCutIntent(this, abstractContact.getAccount(), abstractContact.getUser()));
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, abstractContact.getName());
    Bitmap bitmap;/*from w  w w .  j  ava2  s .c o  m*/
    if (MUCManager.getInstance().hasRoom(abstractContact.getAccount(), abstractContact.getUser())) {
        bitmap = AvatarManager.getInstance().getRoomBitmap(abstractContact.getUser());
    } else {
        bitmap = AvatarManager.getInstance().getUserBitmap(abstractContact.getUser());
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, AvatarManager.getInstance().createShortcutBitmap(bitmap));
    setResult(RESULT_OK, intent);
}

From source file:org.mozilla.gecko.GeckoAppShell.java

public static void createShortcut(final String aTitle, final String aURI, final Bitmap aIcon,
        final String aType) {
    getHandler().post(new Runnable() {
        public void run() {
            Log.w(LOGTAG, "createShortcut for " + aURI + " [" + aTitle + "] > " + aType);

            // the intent to be launched by the shortcut
            Intent shortcutIntent = new Intent();
            if (aType.equalsIgnoreCase("webapp")) {
                shortcutIntent.setAction(GeckoApp.ACTION_WEBAPP);
                shortcutIntent.setData(Uri.parse(aURI));
            } else {
                shortcutIntent.setAction(GeckoApp.ACTION_BOOKMARK);
                shortcutIntent.setData(Uri.parse(aURI));
            }/*from w w  w .  j  a  va 2s.  c o  m*/
            shortcutIntent.setClassName(GeckoApp.mAppContext, GeckoApp.mAppContext.getPackageName() + ".App");

            Intent intent = new Intent();
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
            if (aTitle != null)
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aTitle);
            else
                intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, aURI);
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getLauncherIcon(aIcon));
            intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
            GeckoApp.mAppContext.sendBroadcast(intent);
        }
    });
}