Example usage for android.content Intent EXTRA_SHORTCUT_ICON

List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON

Introduction

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

Prototype

String EXTRA_SHORTCUT_ICON

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

Click Source Link

Document

The name of the extra used to define the icon, as a Bitmap, of a shortcut.

Usage

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

/**
 * Verifies the intent and creates a {@link PendingInstallShortcutInfo}
 *//*from   w ww.  j av a  2s.com*/
private static PendingInstallShortcutInfo createPendingInfo(Context context, Intent data) {
    if (!isValidExtraType(data, Intent.EXTRA_SHORTCUT_INTENT, Intent.class)
            || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.class))
            || !(isValidExtraType(data, Intent.EXTRA_SHORTCUT_ICON, Bitmap.class))) {

        if (DBG)
            Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, context);
    if (info.launchIntent == null || info.label == null) {
        if (DBG)
            Log.e(TAG, "Invalid install shortcut intent");
        return null;
    }

    return convertToLauncherActivityIfPossible(info);
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

private static ArrayList<PendingInstallShortcutInfo> getAndClearInstallQueue(SharedPreferences sharedPrefs) {
    synchronized (sLock) {
        Set<String> strings = sharedPrefs.getStringSet(APPS_PENDING_INSTALL, null);
        if (DBG)//from w w  w.  jav  a2s . c o m
            Log.d(TAG, "Getting and clearing APPS_PENDING_INSTALL: " + strings);
        if (strings == null) {
            return new ArrayList<PendingInstallShortcutInfo>();
        }
        ArrayList<PendingInstallShortcutInfo> infos = new ArrayList<PendingInstallShortcutInfo>();
        for (String json : strings) {
            try {
                JSONObject object = (JSONObject) new JSONTokener(json).nextValue();
                Intent data = Intent.parseUri(object.getString(DATA_INTENT_KEY), 0);
                Intent launchIntent = Intent.parseUri(object.getString(LAUNCH_INTENT_KEY), 0);
                String 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);
                }
                data.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
                PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, launchIntent);
                infos.add(info);
            } catch (org.json.JSONException e) {
                Log.d(TAG, "Exception reading shortcut to add: " + e);
            } catch (java.net.URISyntaxException e) {
                Log.d(TAG, "Exception reading shortcut to add: " + e);
            }
        }
        sharedPrefs.edit().putStringSet(APPS_PENDING_INSTALL, new HashSet<String>()).commit();
        return infos;
    }
}

From source file:net.naonedbus.card.Card.java

private void showMoreAction() {
    final Intent moreIntent = getMoreIntent();
    if (moreIntent != null) {

        final int title = moreIntent.getIntExtra(Intent.EXTRA_TITLE, 0);
        if (title != 0) {
            mMoreActionView.setText(title);
        }//from  ww  w. j  av a2 s.  com

        final int icon = moreIntent.getIntExtra(Intent.EXTRA_SHORTCUT_ICON, 0);
        if (icon != 0) {
            mMoreActionView.setCompoundDrawablesWithIntrinsicBounds(icon, 0, 0, 0);
        }

        mMoreActionView.setVisibility(View.VISIBLE);
        mMoreActionView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(final View v) {
                mContext.startActivity(moreIntent);
            }
        });

    }
}

From source file:com.andernity.launcher2.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from  ww w .ja v a 2  s. co m*/
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0;

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;
    if (mUseInstallQueue || launcherNotLoaded) {
        String spKey = LauncherApplication.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
    } else {
        processInstallShortcut(context, info);
    }
}

From source file:com.ddj.launcher2.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from w w  w .ja  v a2s  . co  m*/
    }

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    boolean launcherNotLoaded = LauncherModel.getCellCountX() <= 0 || LauncherModel.getCellCountY() <= 0;

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;
    if (mUseInstallQueue || launcherNotLoaded) {
        String spKey = LauncherUtil.getSharedPreferencesKey();
        SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
        addToInstallQueue(sp, info);
    } else {
        processInstallShortcut(context, info);
    }
}

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

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from  w w  w .  ja  va2s .c om
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }

    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = ensureValidName(context, intent, data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME)).toString();
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:cc.flydev.launcher.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//from w w  w. ja  v a2  s. c om
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

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

@Override
public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from w  w w  .  j av a  2s. com*/
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

From source file:com.aidy.launcher3.ui.receiver.InstallShortcutReceiver.java

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;//  w w  w. j  a  v  a2 s.com
    }

    if (DBG)
        Log.d(TAG, "Got INSTALL_SHORTCUT: " + data.toUri(0));

    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (intent == null) {
        return;
    }
    // This name is only used for comparisons and notifications, so fall
    // back to activity name
    // if not supplied
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    if (name == null) {
        try {
            PackageManager pm = context.getPackageManager();
            ActivityInfo info = pm.getActivityInfo(intent.getComponent(), 0);
            name = info.loadLabel(pm).toString();
        } catch (PackageManager.NameNotFoundException nnfe) {
            return;
        }
    }
    Bitmap icon = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);
    Intent.ShortcutIconResource iconResource = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);

    // Queue the item up for adding if launcher has not loaded properly yet
    LauncherAppState.setApplicationContext(context.getApplicationContext());
    LauncherAppState app = LauncherAppState.getInstance();
    boolean launcherNotLoaded = (app.getDynamicGrid() == null);

    PendingInstallShortcutInfo info = new PendingInstallShortcutInfo(data, name, intent);
    info.icon = icon;
    info.iconResource = iconResource;

    String spKey = LauncherAppState.getSharedPreferencesKey();
    SharedPreferences sp = context.getSharedPreferences(spKey, Context.MODE_PRIVATE);
    addToInstallQueue(sp, info);
    if (!mUseInstallQueue && !launcherNotLoaded) {
        flushInstallQueue(context);
    }
}

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

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

    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 {// ww w  .j a v a  2 s.  c om
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, displayName);
    }

    mListener.onShortcutIntentCreated(contactUri, intent);
}