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:org.onebusaway.android.util.UIUtils.java

/**
 * Default implementation for creating a shortcut when in shortcut mode.
 *
 * @param name       The name of the shortcut.
 * @param destIntent The destination intent.
 *//*from  www.  j  a v  a 2  s.co  m*/
public static final Intent makeShortcut(Context context, String name, Intent destIntent) {
    // Set up the container intent
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, destIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
    return intent;
}

From source file:com.cleanwiz.applock.ui.activity.SplashActivity.java

public void createDeskShortCut() {
    // ????//  w  w  w . j a  v a  2s .  co m
    SharedPreferenceUtil.editShortCut(true);
    Intent shortcutIntent = new Intent();
    shortcutIntent.setClass(this, SplashActivity.class);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
    shortcutIntent.setAction("android.intent.action.MAIN");
    shortcutIntent.addCategory("android.intent.category.LAUNCHER");

    Intent resultIntent = new Intent();
    resultIntent.putExtra("duplicate", false);
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    resultIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    resultIntent.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
    resultIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    sendBroadcast(resultIntent);
}

From source file:com.dnielfe.manager.AppManager.java

private void createshortcut() {
    Intent shortcutIntent = new Intent(AppManager.this, AppManager.class);
    shortcutIntent.setAction(Intent.ACTION_MAIN);

    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    Intent addIntent = new Intent();
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.appmanager));
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(AppManager.this, R.drawable.type_apk));
    addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
    AppManager.this.sendBroadcast(addIntent);

    Toast.makeText(AppManager.this, getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
}

From source file:com.android.contacts.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);
    final Bitmap icon;
    final Uri phoneUri;
    final String shortcutName;
    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }/* w w  w.  ja  v a  2  s .  c om*/

    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(PhoneAccount.SCHEME_TEL, phoneNumber, null);
        icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel,
                R.drawable.quantum_ic_phone_vd_theme_24);
        shortcutName = mContext.getResources().getString(R.string.call_by_shortcut, displayName);
    } else {
        phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null);
        icon = generatePhoneNumberIcon(drawable, phoneType, phoneLabel,
                R.drawable.quantum_ic_message_vd_theme_24);
        shortcutName = mContext.getResources().getString(R.string.sms_by_shortcut, displayName);
    }

    final Intent shortcutIntent = new Intent(shortcutAction, phoneUri);
    shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

    Intent intent = null;
    IconCompat compatAdaptiveIcon = null;
    if (BuildCompat.isAtLeastO()) {
        compatAdaptiveIcon = IconCompat.createWithAdaptiveBitmap(icon);
        final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE);
        final String id = shortcutAction + lookupKey + phoneUri.toString().hashCode();
        final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
        final ShortcutInfo shortcutInfo = dynamicShortcuts.getActionShortcutInfo(id, displayName,
                shortcutIntent, compatAdaptiveIcon.toIcon());
        if (shortcutInfo != null) {
            intent = sm.createShortcutResultIntent(shortcutInfo);
        }
    }

    intent = intent == null ? new Intent() : intent;
    // This will be non-null in O and above.
    if (compatAdaptiveIcon != null) {
        compatAdaptiveIcon.addToShortcutIntent(intent, null, mContext);
    } else {
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    }
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);

    mListener.onShortcutIntentCreated(uri, intent);
}

From source file:com.marlonjones.voidlauncher.InstallShortcutReceiver.java

private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {//  ww w  . j  a v  a  2s . c o m
        JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
        Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

        if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
            // The is an internal launcher target shortcut.
            UserHandleCompat user = UserManagerCompat.getInstance(context)
                    .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
            if (user == null) {
                return null;
            }

            LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
                    .resolveActivity(launcherIntent, user);
            return info == null ? null : new PendingInstallShortcutInfo(info, context);
        }

        Intent data = new Intent();
        data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
        data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

        String iconBase64 = object.optString(ICON_KEY);
        String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
        String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
        if (iconBase64 != null && !iconBase64.isEmpty()) {
            byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
            Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
        } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
            Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
            iconResource.resourceName = iconResourceName;
            iconResource.packageName = iconResourcePackageName;
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        }

        return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException | URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}

From source file:com.android.launcher3.InstallShortcutReceiver.java

private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {/*from   ww  w .  ja v a 2  s  .  co  m*/
        JSONObject object = (JSONObject) new JSONTokener(encoded).nextValue();
        Intent launcherIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);

        if (object.optBoolean(APP_SHORTCUT_TYPE_KEY)) {
            // The is an internal launcher target shortcut.
            UserHandleCompat user = UserManagerCompat.getInstance(context)
                    .getUserForSerialNumber(object.getLong(USER_HANDLE_KEY));
            if (user == null) {
                return null;
            }

            LauncherActivityInfoCompat info = LauncherAppsCompat.getInstance(context)
                    .resolveActivity(launcherIntent, user);
            return info == null ? null : new PendingInstallShortcutInfo(info, context);
        }

        Intent data = new Intent();
        data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launcherIntent);
        data.putExtra(Intent.EXTRA_SHORTCUT_NAME, object.getString(NAME_KEY));

        String iconBase64 = object.optString(ICON_KEY);
        String iconResourceName = object.optString(ICON_RESOURCE_NAME_KEY);
        String iconResourcePackageName = object.optString(ICON_RESOURCE_PACKAGE_NAME_KEY);
        if (iconBase64 != null && !iconBase64.isEmpty()) {
            byte[] iconArray = Base64.decode(iconBase64, Base64.DEFAULT);
            Bitmap b = BitmapFactory.decodeByteArray(iconArray, 0, iconArray.length);
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON, b);
        } else if (iconResourceName != null && !iconResourceName.isEmpty()) {
            Intent.ShortcutIconResource iconResource = new Intent.ShortcutIconResource();
            iconResource.resourceName = iconResourceName;
            iconResource.packageName = iconResourcePackageName;
            data.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
        }

        return new PendingInstallShortcutInfo(data, context);
    } catch (JSONException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    } catch (URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}

From source file:de.baumann.browser.popups.Popup_readLater.java

private void setReadLaterList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "readLater_title", "readLater_content", "readLater_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0);

    //display data by filter
    final String note_search = sharedPref.getString("filter_readLaterBY", "readLater_title");
    sharedPref.edit().putString("filter_readLaterBY", "readLater_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }/*from www  . j  a v  a2s .co m*/

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String readLater_content = row.getString(row.getColumnIndexOrThrow("readLater_content"));
            sharedPref.edit().putString("openURL", readLater_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String readLater_title = row2.getString(row2.getColumnIndexOrThrow("readLater_title"));
            final String readLater_content = row2.getString(row2.getColumnIndexOrThrow("readLater_content"));
            final String readLater_icon = row2.getString(row2.getColumnIndexOrThrow("readLater_icon"));
            final String readLater_attachment = row2
                    .getString(row2.getColumnIndexOrThrow("readLater_attachment"));
            final String readLater_creation = row2.getString(row2.getColumnIndexOrThrow("readLater_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_readLater.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", readLater_content).apply();
                                sharedPref.edit().putString("edit_icon", readLater_icon).apply();
                                sharedPref.edit().putString("edit_attachment", readLater_attachment).apply();
                                sharedPref.edit().putString("edit_creation", readLater_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_readLater.this, editText, 2, readLater_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setReadLaterList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
                                                            readLater_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT,
                                                            readLater_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_readLater.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", readLater_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_bookmark),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_readLater.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_readLater.this,
                                                            listView, readLater_title, readLater_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_bookmark))) {
                                                    DbAdapter_Bookmarks db = new DbAdapter_Bookmarks(
                                                            Popup_readLater.this);
                                                    db.open();

                                                    if (db.isExist(readLater_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(readLater_title, readLater_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_readLater.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(readLater_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            readLater_content);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_readLater.this
                                                                            .getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_readLater.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });

    listView.post(new Runnable() {
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:de.baumann.browser.popups.Popup_history.java

private void setHistoryList() {

    //display data
    final int layoutstyle = R.layout.list_item;
    int[] xml_id = new int[] { R.id.textView_title_notes, R.id.textView_des_notes, R.id.textView_create_notes };
    String[] column = new String[] { "history_title", "history_content", "history_creation" };
    final Cursor row = db.fetchAllData(this);
    adapter = new SimpleCursorAdapter(this, layoutstyle, row, column, xml_id, 0);

    //display data by filter
    final String note_search = sharedPref.getString("filter_historyBY", "history_title");
    sharedPref.edit().putString("filter_historyBY", "history_title").apply();
    editText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
        }//  ww w  . j  a  v a 2s. c  o m

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            adapter.getFilter().filter(s.toString());
        }
    });
    adapter.setFilterQueryProvider(new FilterQueryProvider() {
        public Cursor runQuery(CharSequence constraint) {
            return db.fetchDataByFilter(constraint.toString(), note_search);
        }
    });

    listView.setAdapter(adapter);
    //onClick function
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterview, View view, int position, long id) {

            Cursor row = (Cursor) listView.getItemAtPosition(position);
            final String history_content = row.getString(row.getColumnIndexOrThrow("history_content"));
            sharedPref.edit().putString("openURL", history_content).apply();
            finish();
        }
    });

    listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            Cursor row2 = (Cursor) listView.getItemAtPosition(position);
            final String _id = row2.getString(row2.getColumnIndexOrThrow("_id"));
            final String history_title = row2.getString(row2.getColumnIndexOrThrow("history_title"));
            final String history_content = row2.getString(row2.getColumnIndexOrThrow("history_content"));
            final String history_icon = row2.getString(row2.getColumnIndexOrThrow("history_icon"));
            final String history_attachment = row2.getString(row2.getColumnIndexOrThrow("history_attachment"));
            final String history_creation = row2.getString(row2.getColumnIndexOrThrow("history_creation"));

            final CharSequence[] options = { getString(R.string.menu_share), getString(R.string.menu_save),
                    getString(R.string.bookmark_edit_title), getString(R.string.bookmark_remove_bookmark) };
            new AlertDialog.Builder(Popup_history.this)
                    .setPositiveButton(R.string.toast_cancel, new DialogInterface.OnClickListener() {

                        public void onClick(DialogInterface dialog, int whichButton) {
                            dialog.cancel();
                        }
                    }).setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals(getString(R.string.bookmark_edit_title))) {
                                sharedPref.edit().putString("edit_id", _id).apply();
                                sharedPref.edit().putString("edit_content", history_content).apply();
                                sharedPref.edit().putString("edit_icon", history_icon).apply();
                                sharedPref.edit().putString("edit_attachment", history_attachment).apply();
                                sharedPref.edit().putString("edit_creation", history_creation).apply();
                                editText.setVisibility(View.VISIBLE);
                                helper_editText.showKeyboard(Popup_history.this, editText, 2, history_title,
                                        getString(R.string.bookmark_edit_title));
                            }

                            if (options[item].equals(getString(R.string.bookmark_remove_bookmark))) {
                                Snackbar snackbar = Snackbar
                                        .make(listView, R.string.bookmark_remove_confirmation,
                                                Snackbar.LENGTH_LONG)
                                        .setAction(R.string.toast_yes, new View.OnClickListener() {
                                            @Override
                                            public void onClick(View view) {
                                                db.delete(Integer.parseInt(_id));
                                                setHistoryList();
                                            }
                                        });
                                snackbar.show();
                            }

                            if (options[item].equals(getString(R.string.menu_share))) {
                                final CharSequence[] options = { getString(R.string.menu_share_link),
                                        getString(R.string.menu_share_link_copy) };
                                new AlertDialog.Builder(Popup_history.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_share_link))) {
                                                    Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                                                    sharingIntent.setType("text/plain");
                                                    sharingIntent.putExtra(Intent.EXTRA_SUBJECT, history_title);
                                                    sharingIntent.putExtra(Intent.EXTRA_TEXT, history_content);
                                                    startActivity(Intent.createChooser(sharingIntent,
                                                            (getString(R.string.app_share_link))));
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_share_link_copy))) {
                                                    ClipboardManager clipboard = (ClipboardManager) Popup_history.this
                                                            .getSystemService(Context.CLIPBOARD_SERVICE);
                                                    clipboard.setPrimaryClip(
                                                            ClipData.newPlainText("text", history_content));
                                                    Snackbar.make(listView, R.string.context_linkCopy_toast,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }
                            if (options[item].equals(getString(R.string.menu_save))) {
                                final CharSequence[] options = { getString(R.string.menu_save_bookmark),
                                        getString(R.string.menu_save_readLater),
                                        getString(R.string.menu_save_pass),
                                        getString(R.string.menu_createShortcut) };
                                new AlertDialog.Builder(Popup_history.this)
                                        .setPositiveButton(R.string.toast_cancel,
                                                new DialogInterface.OnClickListener() {

                                                    public void onClick(DialogInterface dialog,
                                                            int whichButton) {
                                                        dialog.cancel();
                                                    }
                                                })
                                        .setItems(options, new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialog, int item) {
                                                if (options[item].equals(getString(R.string.menu_save_pass))) {
                                                    helper_editText.editText_savePass(Popup_history.this,
                                                            listView, history_title, history_content);
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_bookmark))) {

                                                    DbAdapter_Bookmarks db = new DbAdapter_Bookmarks(
                                                            Popup_history.this);
                                                    db.open();

                                                    if (db.isExist(history_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(history_title, history_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_save_readLater))) {
                                                    DbAdapter_ReadLater db = new DbAdapter_ReadLater(
                                                            Popup_history.this);
                                                    db.open();
                                                    if (db.isExist(history_content)) {
                                                        Snackbar.make(listView,
                                                                getString(R.string.toast_newTitle),
                                                                Snackbar.LENGTH_LONG).show();
                                                    } else {
                                                        db.insert(history_title, history_content, "", "",
                                                                helper_main.createDate());
                                                        Snackbar.make(listView, R.string.bookmark_added,
                                                                Snackbar.LENGTH_LONG).show();
                                                    }
                                                }
                                                if (options[item]
                                                        .equals(getString(R.string.menu_createShortcut))) {
                                                    Intent i = new Intent();
                                                    i.setAction(Intent.ACTION_VIEW);
                                                    i.setClassName(Popup_history.this,
                                                            "de.baumann.browser.Browser_left");
                                                    i.setData(Uri.parse(history_content));

                                                    Intent shortcut = new Intent();
                                                    shortcut.putExtra("android.intent.extra.shortcut.INTENT",
                                                            i);
                                                    shortcut.putExtra("android.intent.extra.shortcut.NAME",
                                                            "THE NAME OF SHORTCUT TO BE SHOWN");
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                                                            history_title);
                                                    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                                                            Intent.ShortcutIconResource.fromContext(
                                                                    Popup_history.this.getApplicationContext(),
                                                                    R.mipmap.ic_launcher));
                                                    shortcut.setAction(
                                                            "com.android.launcher.action.INSTALL_SHORTCUT");
                                                    Popup_history.this.sendBroadcast(shortcut);
                                                    Snackbar.make(listView,
                                                            R.string.menu_createShortcut_success,
                                                            Snackbar.LENGTH_SHORT).show();
                                                }
                                            }
                                        }).show();
                            }

                        }
                    }).show();
            return true;
        }
    });

    listView.post(new Runnable() {
        public void run() {
            listView.setSelection(listView.getCount() - 1);
        }
    });
}

From source file:org.zywx.wbpalmstar.engine.EUtil.java

public final void createSystemSwitcherShortCut(Context context, String shortCutName) {
    Intent addIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    Parcelable icon = Intent.ShortcutIconResource.fromContext(context, EResources.icon);
    addIntent.putExtra("duplicate", false);
    Intent targetIntent = new Intent(context, EBrowserActivity.class);
    targetIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortCutName);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
    context.sendBroadcast(addIntent);/*from  w ww .  ja  va  2 s . c o  m*/
}

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;//from   ww  w  . j  a v a2s.  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);
}