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:library.artaris.cn.library.utils.SystemUtils.java

/**
 * ??//from ww w  .j a va  2s . co 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.dnielfe.manager.utils.SimpleUtils.java

public static void createShortcut(Activity main, String path) {
    File file = new File(path);

    try {/*  ww w .  j  a v  a2  s  .  c o  m*/
        // Create the intent that will handle the shortcut
        Intent shortcutIntent = new Intent(main, Browser.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        shortcutIntent.putExtra(Browser.EXTRA_SHORTCUT, path);

        // The intent to send to broadcast for register the shortcut intent
        Intent intent = new Intent();
        intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
        intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, file.getName());
        intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
                Intent.ShortcutIconResource.fromContext(main, R.drawable.ic_launcher));
        intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
        main.sendBroadcast(intent);

        Toast.makeText(main, main.getString(R.string.shortcutcreated), Toast.LENGTH_SHORT).show();
    } catch (Exception e) {
        Toast.makeText(main, main.getString(R.string.error), Toast.LENGTH_SHORT).show();
    }
}

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 ava2 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.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.cleanwiz.applock.ui.activity.SplashActivity.java

public void createDeskShortCut() {
    // ????//from   ww w.  j  av a2  s  . c om
    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: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   ww w .  ja  v  a  2 s .  c  om*/
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.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.marlonjones.voidlauncher.InstallShortcutReceiver.java

private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {/*from   ww w . j a  v a2s  .  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 {/*  w ww  .jav 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 e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    } catch (URISyntaxException e) {
        Log.d(TAG, "Exception reading shortcut to add: " + e);
    }
    return null;
}