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:com.jefftharris.passwdsafe.PreferencesFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case REQUEST_DEFAULT_FILE: {
        if (resultCode != Activity.RESULT_OK) {
            break;
        }//from   ww  w . ja va2  s.  co  m
        Intent val = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
        setDefFilePref((val != null) ? val.getData().toString() : null);
        break;
    }
    default: {
        super.onActivityResult(requestCode, resultCode, data);
        break;
    }
    }
}

From source file:fi.iki.murgo.irssinotifier.SettingsActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode != ICB_HOST_REQUEST_CODE) {
        return;// w  w  w. j  a v a  2 s .c  o m
    }

    Preferences prefs = new Preferences(this);

    if (data == null || resultCode != Activity.RESULT_OK) {
        prefs.setIcbHost(null, null);
    } else {
        String hostName = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
        Intent intent = (Intent) data.getExtras().get(Intent.EXTRA_SHORTCUT_INTENT);
        if (intent != null) {
            String intentUri = intent.toUri(0);
            prefs.setIcbHost(hostName, intentUri);
        } else {
            prefs.setIcbHost(null, null);
        }
    }

    handleIcb();
}

From source file:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ??//from   w  ww  .java  2 s  .c o m
 * @param context
 * @param shortCutName
 * @param iconId
 * @param presentIntent
 */
public static void createShortcut(Context context, 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(context, iconId));
    shortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, presentIntent);
    context.sendBroadcast(shortcutIntent);
}

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

private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName,
        String lookupKey, byte[] bitmapData) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    // Use an implicit intent without a package name set. It is reasonable for a disambiguation
    // dialog to appear when opening QuickContacts from the launcher. Plus, this will be more
    // resistant to future package name changes done to Contacts.
    Intent shortcutIntent = new Intent(ContactsContract.QuickContact.ACTION_QUICK_CONTACT);

    // When starting from the launcher, start in a new, cleared task.
    // CLEAR_WHEN_TASK_RESET cannot reset the root of a task, so we
    // clear the whole thing preemptively here since QuickContactActivity will
    // finish itself when launching other detail activities. We need to use
    // Intent.FLAG_ACTIVITY_NO_ANIMATION since not all versions of launcher will respect
    // the INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION intent extra.
    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK
            | Intent.FLAG_ACTIVITY_NO_ANIMATION);

    // Tell the launcher to not do its animation, because we are doing our own
    shortcutIntent.putExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION, true);

    shortcutIntent.setDataAndType(contactUri, contentType);
    shortcutIntent.putExtra(ContactsContract.QuickContact.EXTRA_EXCLUDE_MIMES, (String[]) null);

    final Bitmap icon = generateQuickContactIcon(drawable);

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    if (TextUtils.isEmpty(displayName)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, mContext.getResources().getString(R.string.missing_name));
    } else {/*  w  w w.  j a v a  2s.co m*/
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
    }

    mListener.onShortcutIntentCreated(contactUri, intent);
}

From source file:org.protocoder.appApi.ProtoScripts.java

public void addShortcut(String folder, String name) {
    Project p = ProjectManager.getInstance().get(folder, name);

    Intent.ShortcutIconResource icon;//from w ww  .  j a  v  a 2  s  . c o m
    //TODO remove this way of selecting icons
    if (folder.equals("examples")) {
        icon = Intent.ShortcutIconResource.fromContext(mProtocoder.a, R.drawable.protocoder_script_example);
    } else {
        icon = Intent.ShortcutIconResource.fromContext(mProtocoder.a, R.drawable.protocoder_script_project);
    }

    try {
        Intent shortcutIntent = new Intent(mProtocoder.a, AppRunnerActivity.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);

        String script = ProjectManager.getInstance().getCode(p);
        shortcutIntent.putExtra(Project.NAME, p.getName());
        shortcutIntent.putExtra(Project.FOLDER, p.getFolder());

        final Intent putShortCutIntent = new Intent();

        putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, p.getName());
        putShortCutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
        putShortCutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        mProtocoder.a.sendBroadcast(putShortCutIntent);
    } catch (Exception e) {
        // TODO
    }
    // Show toast
    Toast.makeText(mProtocoder.a, "Adding shortcut for " + p.getName(), Toast.LENGTH_SHORT).show();
}

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

private void createContactShortcutIntent(Uri contactUri, String contentType, String displayName,
        String lookupKey, byte[] bitmapData) {
    Intent intent = null;/*from   ww  w . j ava2s . co  m*/
    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }
    if (BuildCompat.isAtLeastO()) {
        final long contactId = ContentUris.parseId(contactUri);
        final ShortcutManager sm = (ShortcutManager) mContext.getSystemService(Context.SHORTCUT_SERVICE);
        final DynamicShortcuts dynamicShortcuts = new DynamicShortcuts(mContext);
        final ShortcutInfo shortcutInfo = dynamicShortcuts.getQuickContactShortcutInfo(contactId, lookupKey,
                displayName);
        if (shortcutInfo != null) {
            intent = sm.createShortcutResultIntent(shortcutInfo);
        }
    }
    final Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    final Intent shortcutIntent = ImplicitIntentsUtil.getIntentForQuickContactLauncherShortcut(mContext,
            contactUri);

    intent = intent == null ? new Intent() : intent;

    final Bitmap icon = generateQuickContactIcon(drawable);
    if (BuildCompat.isAtLeastO()) {
        final IconCompat compatIcon = IconCompat.createWithAdaptiveBitmap(icon);
        compatIcon.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, displayName);

    mListener.onShortcutIntentCreated(contactUri, intent);
}

From source file:com.todoroo.astrid.activity.FilterListFragment.java

/**
 * Creates a shortcut on the user's home screen
 *
 * @param shortcutIntent//from   ww w  .  j av a  2  s. co m
 * @param label
 */
private static void createShortcut(Activity activity, Filter filter, Intent shortcutIntent, String label) {
    if (label.length() == 0)
        return;

    Bitmap bitmap = superImposeListIcon(activity, filter.listingIcon, filter.listingTitle);

    Intent createShortcutIntent = new Intent();
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, label);
    createShortcutIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    createShortcutIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); //$NON-NLS-1$

    activity.sendBroadcast(createShortcutIntent);
    Toast.makeText(activity, activity.getString(R.string.FLA_toast_onCreateShortcut, label), Toast.LENGTH_LONG)
            .show();
}

From source file:com.duy.pascal.ui.file.FileManager.java

public Intent createShortcutIntent(Context context, File file) {
    // create shortcut if requested
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(context, R.mipmap.ic_launcher);

    Intent intent = new Intent();

    Intent launchIntent = new Intent(context, SplashScreenActivity.class);
    launchIntent.putExtra(CompileManager.EXTRA_FILE, file);
    launchIntent.setAction("run_from_shortcut");

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    return intent;
}

From source file:com.silentcircle.contacts.list.ShortcutIntentBuilder.java

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap = null;/*from   w w w .j  a va 2 s .  com*/
    Uri phoneUri = null;
    if (Intent.ACTION_CALL.equals(shortcutAction)) {
        // Make the URI a direct tel: URI so that it will always continue to work
        phoneUri = Uri.fromParts(Constants.SCHEME_TEL, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.badge_action_call);
        //        } else {
        //            phoneUri = Uri.fromParts(Constants.SCHEME_SMSTO, phoneNumber, null);
        //            bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel,
        //                    R.drawable.badge_action_sms);
    }

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

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);

    mListener.onShortcutIntentCreated(uri, intent);
}

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

private void createPhoneNumberShortcutIntent(Uri uri, String displayName, String lookupKey, byte[] bitmapData,
        String phoneNumber, int phoneType, String phoneLabel, String shortcutAction) {
    Drawable drawable = getPhotoDrawable(bitmapData, displayName, lookupKey);

    Bitmap bitmap;/*from ww  w  . ja va 2s.co  m*/
    Uri phoneUri;
    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);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_call);
    } else {
        phoneUri = Uri.fromParts(ContactsUtils.SCHEME_SMSTO, phoneNumber, null);
        bitmap = generatePhoneNumberIcon(drawable, phoneType, phoneLabel, R.drawable.ic_message_24dp);
    }

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

    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, bitmap);
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);

    if (TextUtils.isEmpty(displayName)) {
        displayName = mContext.getResources().getString(R.string.missing_name);
    }
    if (TextUtils.equals(shortcutAction, Intent.ACTION_CALL)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.call_by_shortcut, displayName));
    } else if (TextUtils.equals(shortcutAction, Intent.ACTION_SENDTO)) {
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME,
                mContext.getResources().getString(R.string.sms_by_shortcut, displayName));
    }

    mListener.onShortcutIntentCreated(uri, intent);
}