Example usage for android.content Intent EXTRA_SHORTCUT_NAME

List of usage examples for android.content Intent EXTRA_SHORTCUT_NAME

Introduction

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

Prototype

String EXTRA_SHORTCUT_NAME

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

Click Source Link

Document

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

Usage

From source file:com.android.contacts.quickcontact.QuickContactActivity.java

/**
 * Creates a launcher shortcut with the current contact.
 *//* ww w . ja  v  a 2  s .  co  m*/
private void createLauncherShortcutWithContact() {
    final ShortcutIntentBuilder builder = new ShortcutIntentBuilder(this,
            new OnShortcutIntentCreatedListener() {

                @Override
                public void onShortcutIntentCreated(Uri uri, Intent shortcutIntent) {
                    // Broadcast the shortcutIntent to the launcher to create a
                    // shortcut to this contact
                    shortcutIntent.setAction(ACTION_INSTALL_SHORTCUT);
                    QuickContactActivity.this.sendBroadcast(shortcutIntent);

                    // Send a toast to give feedback to the user that a shortcut to this
                    // contact was added to the launcher.
                    final String displayName = shortcutIntent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
                    final String toastMessage = TextUtils.isEmpty(displayName)
                            ? getString(R.string.createContactShortcutSuccessful_NoName)
                            : getString(R.string.createContactShortcutSuccessful, displayName);
                    Toast.makeText(QuickContactActivity.this, toastMessage, Toast.LENGTH_SHORT).show();
                }

            });
    builder.createContactShortcutIntent(mContactData.getLookupUri());
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void pickShortcut(int requestCode, int title) {
    Bundle bundle = new Bundle();
    /*//from w w w.j a  va2s .  c o m
          ArrayList<String> shortcutNames = new ArrayList<String>();
          shortcutNames.add(getString(R.string.group_applications));
          bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames);
            
          ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>();
          shortcutIcons.add(ShortcutIconResource.fromContext(
    PersonaLauncher.this, R.drawable.pr_ic_launcher_application));
          bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
    shortcutIcons);*/
    //   Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY);
    Intent pickIntent = new Intent();

    String ShortCutName = new String(getString(R.string.group_applications));
    bundle.putString(Intent.EXTRA_SHORTCUT_NAME, ShortCutName);

    pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT));
    pickIntent.putExtra(Intent.EXTRA_TITLE, getString(R.string.group_applications));
    pickIntent.putExtras(bundle);
    processShortcut(pickIntent, REQUEST_PICK_APPLICATION, REQUEST_CREATE_SHORTCUT);
    //startActivityForResult(pickIntent, requestCode);
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void completeEditShirtcut(Intent data) {
    if (!data.hasExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO))
        return;//from  ww w .  j a va 2  s  .c  o  m
    long appInfoId = data.getLongExtra(PersonaCustomShirtcutActivity.EXTRA_APPLICATIONINFO, 0);
    PersonaApplicationInfo info = PersonaLauncherModel.loadApplicationInfoById(this, appInfoId);
    if (info != null) {
        Bitmap bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);

        Drawable icon = null;
        boolean customIcon = false;
        ShortcutIconResource iconResource = null;

        if (bitmap != null) {
            icon = new PersonaFastBitmapDrawable(PersonaUtilities.createBitmapThumbnail(bitmap, this));
            customIcon = true;
        } else {
            Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (extra != null && extra instanceof ShortcutIconResource) {
                try {
                    iconResource = (ShortcutIconResource) extra;
                    final PackageManager packageManager = getPackageManager();
                    Resources resources = packageManager.getResourcesForApplication(iconResource.packageName);
                    final int id = resources.getIdentifier(iconResource.resourceName, null, null);
                    icon = resources.getDrawable(id);
                } catch (Exception e) {
                    PersonaLog.w(LOG_TAG, "Could not load shortcut icon: " + extra);
                }
            }
        }

        if (icon != null) {
            info.icon = icon;
            info.customIcon = customIcon;
            info.iconResource = iconResource;
        }
        info.itemType = PersonaLauncherSettings.Favorites.ITEM_TYPE_SHORTCUT;
        info.title = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
        info.intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        PersonaLauncherModel.updateItemInDatabase(this, info);

        if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_MAB)
            mHandleView.UpdateLaunchInfo(info);
        else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB)
            mLAB.UpdateLaunchInfo(info);
        else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_LAB2)
            mLAB2.UpdateLaunchInfo(info);
        else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB)
            mRAB.UpdateLaunchInfo(info);
        else if (info.container == PersonaLauncherSettings.Favorites.CONTAINER_RAB2)
            mRAB2.UpdateLaunchInfo(info);

        mWorkspace.updateShortcutFromApplicationInfo(info);
    }
}