Example usage for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

List of usage examples for android.content Intent EXTRA_SHORTCUT_ICON_RESOURCE

Introduction

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

Prototype

String EXTRA_SHORTCUT_ICON_RESOURCE

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

Click Source Link

Document

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

Usage

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)// ww w.  ja v a2  s .  com
            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.gsantner.opoc.util.ShareUtil.java

/**
 * Try to create a new desktop shortcut on the launcher. This will not work on Api > 25. Add permissions:
 * <uses-permission android:name="android.permission.INSTALL_SHORTCUT" />
 * <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 *
 * @param intent  The intent to be invoked on tap
 * @param iconRes Icon resource for the item
 * @param title   Title of the item/* w  ww . j  a  v  a  2s.c om*/
 */
public void createLauncherDesktopShortcutLegacy(Intent intent, @DrawableRes int iconRes, String title) {
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    if (intent.getAction() == null) {
        intent.setAction(Intent.ACTION_VIEW);
    }

    Intent creationIntent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    creationIntent.putExtra("duplicate", true);
    creationIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
    creationIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    creationIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(_context, iconRes));
    _context.sendBroadcast(creationIntent);
}

From source file:org.wso2.emm.agent.api.ApplicationManager.java

/**
 * Creates a webclip on the device home screen.
 * @param url   - URL should be passed in as a String.
 * @param title - Title(Web app title) should be passed in as a String.
 *///from  w ww  .  j ava 2  s.  co  m
public void manageWebAppBookmark(String url, String title, String operationType) throws AndroidAgentException {
    final Intent bookmarkIntent = new Intent();
    final Intent actionIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    long urlHash = url.hashCode();
    long uniqueId = (urlHash << MAX_URL_HASH) | actionIntent.hashCode();

    actionIntent.putExtra(Browser.EXTRA_APPLICATION_ID, Long.toString(uniqueId));
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, actionIntent);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);
    bookmarkIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(context, R.drawable.ic_bookmark));
    if (operationType != null) {
        if (resources.getString(R.string.operation_install).equalsIgnoreCase(operationType)) {
            bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
        } else if (resources.getString(R.string.operation_uninstall).equalsIgnoreCase(operationType)) {
            bookmarkIntent
                    .setAction(resources.getString(R.string.application_package_launcher_uninstall_action));
        } else {
            throw new AndroidAgentException("Cannot create webclip due to invalid operation type.");
        }
    } else {
        bookmarkIntent.setAction(resources.getString(R.string.application_package_launcher_install_action));
    }
    context.sendBroadcast(bookmarkIntent);
}

From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesActivity.java

private void createShortcut() {
    Intent shortcutIntent = new Intent(this, PreferencesActivity.class);
    shortcutIntent.putExtra(EXTRA_PACKAGE_NAME, packageName);
    shortcutIntent.putExtra(EXTRA_TITLE, title);
    shortcutIntent.putExtra(EXTRA_SHORTCUT, true);
    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, title);
    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
            Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher));
    addIntent.setAction(INSTALL_SHORTCUT);
    sendBroadcast(addIntent);//  ww w  . j  a  v a  2  s  . c o  m
}

From source file:com.example.android.MyVoice.MainActivity.java

public void createShortCut() {
    Intent shortcutintent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
    shortcutintent.putExtra("duplicate", false);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.shortcutname));
    Parcelable icon = Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.myvoice_icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);
    shortcutintent.putExtra(Intent.EXTRA_SHORTCUT_INTENT,
            new Intent(getApplicationContext(), MainActivity.class));
    sendBroadcast(shortcutintent);//from   ww  w.  j  a  v a2  s  . c  om
}

From source file:com.jefftharris.passwdsafe.LauncherRecordShortcuts.java

/**
 * Select the given record and return a result
 *///from  w ww  .  j  a v  a 2 s . c  o  m
private void selectRecord(final String uuid) {
    switch (itsMode) {
    case SHORTCUT: {
        final ObjectHolder<Pair<Uri, String>> rc = new ObjectHolder<>();
        PasswdSafeFileDataFragment.useOpenFileData(new PasswdFileDataUser() {
            @Override
            public void useFileData(@NonNull PasswdFileData fileData) {
                PwsRecord rec = fileData.getRecord(uuid);
                String title = fileData.getTitle(rec);
                rc.set(new Pair<>(fileData.getUri().getUri(), title));
            }
        });
        Pair<Uri, String> rcval = rc.get();
        if (rcval != null) {
            Intent shortcutIntent = PasswdSafeUtil.createOpenIntent(rcval.first, uuid);

            Intent intent = new Intent();
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
            intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, rcval.second);
            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                    Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_passwdsafe));
            setResult(RESULT_OK, intent);
        }
        break;
    }
    case CHOOSE_RECORD: {
        Intent intent = new Intent();
        intent.putExtra(PasswdSafeApp.RESULT_DATA_UUID, uuid);
        setResult(RESULT_OK, intent);
        break;
    }
    }
    finish();
}

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

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from   w  w w  .j av  a2 s . c o 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:uk.org.rivernile.edinburghbustracker.android.fragments.general.FavouriteStopsFragment.java

/**
 * {@inheritDoc}/*from   w w  w. ja v a2  s.  com*/
 */
@Override
public void onListItemClick(final ListView l, final View v, final int position, final long id) {
    // Get the stopCode and cache the Activity.
    final String stopCode = String.valueOf(id);
    final Activity activity = getActivity();
    Intent intent;

    // What happens when the user selects a list item depends on what mode
    // is active.
    if (isCreateShortcut) {
        // Set the Intent which is used when the shortcut is tapped.
        intent = new Intent(Intent.ACTION_MAIN);
        intent.setClass(activity, DisplayStopDataActivity.class);
        intent.setAction(DisplayStopDataActivity.ACTION_VIEW_STOP_DATA);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        intent.putExtra(DisplayStopDataActivity.ARG_STOPCODE, stopCode);

        // Set the Activity result to send back to the launcher, which
        // contains a name, Intent and icon.
        final Intent result = new Intent();
        result.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
        result.putExtra(Intent.EXTRA_SHORTCUT_NAME, sd.getNameForStop(stopCode));
        final Parcelable icon = Intent.ShortcutIconResource.fromContext(activity, R.drawable.appicon_favourite);
        result.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

        // Set the Activity result and exit.
        activity.setResult(Activity.RESULT_OK, result);
        activity.finish();
    } else {
        // View bus stop times.
        callbacks.onShowBusTimes(stopCode);
    }
}

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

public void onReceive(Context context, Intent data) {
    if (!ACTION_INSTALL_SHORTCUT.equals(data.getAction())) {
        return;/*from ww w.j  a v a 2s .  c  o  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.josephblough.sbt.activities.ShortcutActivity.java

private void createLauncher(final int searchType, final String criteria) {
    Intent shortcutIntent = new Intent(Intent.ACTION_MAIN);
    shortcutIntent.setClassName(this, this.getClass().getName());
    shortcutIntent.putExtra(SEARCH_TYPE, searchType);
    if (criteria != null)
        shortcutIntent.putExtra(CRITERIA, criteria); // Pass back the criteria from the activity

    // 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, ITEMS[searchType]);
    Parcelable iconResource = Intent.ShortcutIconResource.fromContext(this, ICONS[searchType]);
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);

    // Return the result to the launcher
    setResult(RESULT_OK, intent);/* w w  w  . j  a  v  a 2 s . c  om*/
    finish();
}