Java Code Examples for android.content.Intent.ShortcutIconResource

The following are Jave code examples for showing how to use ShortcutIconResource of the android.content.Intent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: javaide   File: FileManager.java   View Source Code Vote up 7 votes
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.FILE_PATH, file.getPath());
    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;
}
 
Example 2
Project: container   File: BroadcastIntent.java   View Source Code Vote up 7 votes
private Intent handleInstallShortcutIntent(Intent intent) {
    Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (shortcut != null) {
        ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
        if (component != null) {
            String pkg = component.getPackageName();
            Intent newShortcutIntent = new Intent();
            newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
            newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
            newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
            newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
            newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
            intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);

            Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
                try {
                    Resources resources = VirtualCore.get().getResources(pkg);
                    if (resources != null) {
                        int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
                        if (resId > 0) {
                            Drawable iconDrawable = resources.getDrawable(resId);
                            Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
                            if (newIcon != null) {
                                intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                                intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
                            }
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return intent;
}
 
Example 3
Project: https-github.com-hyb1996-NoRootScriptDroid   File: Shortcut.java   View Source Code Vote up 6 votes
public Shortcut iconRes(Intent.ShortcutIconResource icon) {
    if (mIcon != null) {
        throw new IllegalStateException("Cannot set both iconRes and icon");
    }
    mIconRes = icon;
    return this;
}
 
Example 4
Project: LaunchEnr   File: InstallShortcutReceiver.java   View Source Code Vote up 6 votes
private static ShortcutInfo createShortcutInfo(Intent data, LauncherAppState app) {
    Intent intent = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    String name = data.getStringExtra(Intent.EXTRA_SHORTCUT_NAME);
    Parcelable bitmap = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON);

    if (intent == null) {
        // If the intent is null, we can't construct a valid ShortcutInfo, so we return null
        return null;
    }

    final ShortcutInfo info = new ShortcutInfo();

    // Only support intents for current user for now. Intents sent from other
    // users wouldn't get here without intent forwarding anyway.
    info.user = Process.myUserHandle();

    if (bitmap instanceof Bitmap) {
        info.iconBitmap = LauncherIcons.createIconBitmap((Bitmap) bitmap, app.getContext());
    } else {
        Parcelable extra = data.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
        if (extra instanceof Intent.ShortcutIconResource) {
            info.iconResource = (Intent.ShortcutIconResource) extra;
            info.iconBitmap = LauncherIcons.createIconBitmap(info.iconResource, app.getContext());
        }
    }
    if (info.iconBitmap == null) {
        info.iconBitmap = app.getIconCache().getDefaultIcon(info.user);
    }

    info.title = Utilities.trim(name);
    info.contentDescription = UserManagerCompat.getInstance(app.getContext())
            .getBadgedLabelForUser(info.title, info.user);
    info.intent = intent;
    return info;
}
 
Example 5
Project: sflauncher   File: App.java   View Source Code Vote up 6 votes
public Shortcut(Context ctx, Intent i, String name, Intent.ShortcutIconResource icon){
    super(name);
    this.packageName = icon.packageName;
    this.intent = i;
    try {
        Resources res = ctx.getPackageManager().getResourcesForApplication(icon.packageName);
        this.drawableIdent = res.getIdentifier(icon.resourceName, "drawable", icon.packageName);
        this.icon = res.getDrawable(drawableIdent);
    } catch (PackageManager.NameNotFoundException e) {
        this.icon = ctx.getResources().getDrawable(R.drawable.ic_launcher);

    }
}
 
Example 6
Project: text_converter   File: CreateShortcutActivity.java   View Source Code Vote up 6 votes
private void onSuccess() {
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, getShortcutIcon());

    Intent intent = new Intent();

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getOpenShortcutActivityIntent());
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getShortcutName());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);
    finish();
}
 
Example 7
Project: text_converter   File: FloatingCodecCreateShortCutActivity.java   View Source Code Vote up 6 votes
private void onSuccess() {
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_round);

    Intent intent = new Intent();
    Intent launchIntent = new Intent(this, FloatingCodecOpenShortCutActivity.class);

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);
    finish();
}
 
Example 8
Project: text_converter   File: FloatingStylishCreateShortCutActivity.java   View Source Code Vote up 6 votes
private void onSuccess() {
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.mipmap.ic_launcher_round);

    Intent intent = new Intent();
    Intent launchIntent = new Intent(this, FloatingStylishOpenShortCutActivity.class);

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);
    finish();
}
 
Example 9
Project: floating_calc   File: CreateShortcutActivity.java   View Source Code Vote up 6 votes
private void onSuccess() {
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, getShortcutIcon());

    Intent intent = new Intent();

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getOpenShortcutActivityIntent());
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getShortcutName());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);
    finish();
}
 
Example 10
Project: floating_calc   File: FloatingCreateShortCutActivity.java   View Source Code Vote up 6 votes
private void onSuccess() {
    Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher_floating);

    Intent intent = new Intent();
    Intent launchIntent = new Intent(this, FloatingOpenShortCutActivity.class);

    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, getString(R.string.app_name));
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

    setResult(RESULT_OK, intent);
    finish();
}
 
Example 11
Project: lrs_android   File: AppUtil.java   View Source Code Vote up 6 votes
/**
 * 创建桌面快捷方式
 *
 * @param resId 应用图标
 *              <uses-permission android:NAME="com.android.launcher.permission.INSTALL_SHORTCUT" />
 */
public static void createShortcut(Context context, int resId) {
    Intent shortcut = new Intent("com.android.launcher.doRoleAction.INSTALL_SHORTCUT");
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, context.getString(R.string.app_name));
    shortcut.putExtra("duplicate", false);
    ComponentName comp = new ComponentName(context.getPackageName(), "." + ((Activity) context).getLocalClassName());
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(Intent.ACTION_MAIN).setComponent(comp));
    Intent.ShortcutIconResource iconRes = Intent.ShortcutIconResource.fromContext(context, resId);
    shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconRes);
    context.sendBroadcast(shortcut);
}
 
Example 12
Project: Auto.js   File: Shortcut.java   View Source Code Vote up 6 votes
public Shortcut iconRes(Intent.ShortcutIconResource icon) {
    if (mIcon != null) {
        throw new IllegalStateException("Cannot set both iconRes and icon");
    }
    mIconRes = icon;
    return this;
}
 
Example 13
Project: orgzly-android   File: BookChooserActivity.java   View Source Code Vote up 6 votes
@Override
public void onBookClicked(long bookId) {
    if (action != null && action.equals(Intent.ACTION_CREATE_SHORTCUT)) {

        /* If this intent is used, shortcut's label will be overwritten (set to "Orgzly")
         * with some launchers (like Nova) on every app update.
         * It looks like it's due to setting action to ACTION_MAIN and category to
         * CATEGORY_LAUNCHER (which main activity uses)
         */
         // Intent launchIntent = Intent.makeRestartActivityTask(new ComponentName(this, MainActivity.class));

        Intent launchIntent = new Intent(this, MainActivity.class);
        launchIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        launchIntent.putExtra(AppIntent.EXTRA_BOOK_ID, bookId);

        Intent shortcut = new Intent(Intent.ACTION_CREATE_SHORTCUT);

        Shelf shelf = new Shelf(this);
        String title = BookUtils.getFragmentTitleForBook(shelf.getBook(bookId));
        if (title == null) {
            setResult(RESULT_CANCELED, shortcut);
            finish();
            return;
        }
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, title);

        Intent.ShortcutIconResource icon = Intent.ShortcutIconResource.fromContext(this, R.drawable.cic_orgzly_logo_with_notebook);
        shortcut.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, icon);

        shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, launchIntent);

        setResult(RESULT_OK, shortcut);
        finish();
    }
}
 
Example 14
Project: TPlayer   File: MethodProxies.java   View Source Code Vote up 6 votes
private Intent handleInstallShortcutIntent(Intent intent) {
    Intent shortcut = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_INTENT);
    if (shortcut != null) {
        ComponentName component = shortcut.resolveActivity(VirtualCore.getPM());
        if (component != null) {
            String pkg = component.getPackageName();
            Intent newShortcutIntent = new Intent();
            newShortcutIntent.setClassName(getHostPkg(), Constants.SHORTCUT_PROXY_ACTIVITY_NAME);
            newShortcutIntent.addCategory(Intent.CATEGORY_DEFAULT);
            newShortcutIntent.putExtra("_VA_|_intent_", shortcut);
            newShortcutIntent.putExtra("_VA_|_uri_", shortcut.toUri(0));
            newShortcutIntent.putExtra("_VA_|_user_id_", VUserHandle.myUserId());
            intent.removeExtra(Intent.EXTRA_SHORTCUT_INTENT);
            intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, newShortcutIntent);

            Intent.ShortcutIconResource icon = intent.getParcelableExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
            if (icon != null && !TextUtils.equals(icon.packageName, getHostPkg())) {
                try {
                    Resources resources = VirtualCore.get().getResources(pkg);
                    int resId = resources.getIdentifier(icon.resourceName, "drawable", pkg);
                    if (resId > 0) {
                        //noinspection deprecation
                        Drawable iconDrawable = resources.getDrawable(resId);
                        Bitmap newIcon = BitmapUtils.drawableToBitmap(iconDrawable);
                        if (newIcon != null) {
                            intent.removeExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE);
                            intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, newIcon);
                        }
                    }
                } catch (Throwable e) {
                    e.printStackTrace();
                }
            }
        }
    }
    return intent;
}
 
Example 15
Project: phonk   File: PhonkScriptHelper.java   View Source Code Vote up 6 votes
public static void addShortcut(Context c, String folder, String name) {
    Project p = new Project(folder, name);

    Intent.ShortcutIconResource icon;
    icon = Intent.ShortcutIconResource.fromContext(c, R.drawable.app_icon);

    try {
        Intent shortcutIntent = new Intent(c, AppRunnerActivity.class);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        shortcutIntent.putExtra(Project.NAME, p.getName());
        shortcutIntent.putExtra(Project.FOLDER, p.getFolder());

        Map<String, Object> map = AppRunnerHelper.readProjectProperties(c, p);

        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");
        c.sendBroadcast(putShortCutIntent);
    } catch (Exception e) {
        // TODO
    }
    // Show toast
    Toast.makeText(c, "Adding shortcut for " + p.getName(), Toast.LENGTH_SHORT).show();

}
 
Example 16
Project: https-github.com-hyb1996-NoRootScriptDroid   File: Shortcut.java   View Source Code Vote up 5 votes
public Intent.ShortcutIconResource getIconRes() {
    return mIconRes;
}
 
Example 17
Project: LaunchEnr   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
String encodeToString() {
    try {
        if (activityInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                .object()
                .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                .key(APP_SHORTCUT_TYPE_KEY).value(true)
                .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                        .getSerialNumberForUser(user))
                .endObject().toString();
        } else if (shortcutInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                    .object()
                    .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                    .key(DEEPSHORTCUT_TYPE_KEY).value(true)
                    .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                            .getSerialNumberForUser(user))
                    .endObject().toString();
        } else if (providerInfo != null) {
            // If it a launcher target, we only need component name, and user to
            // recreate this.
            return new JSONStringer()
                    .object()
                    .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
                    .key(APP_WIDGET_TYPE_KEY).value(true)
                    .key(USER_HANDLE_KEY).value(UserManagerCompat.getInstance(mContext)
                            .getSerialNumberForUser(user))
                    .endObject().toString();
        }

        if (launchIntent.getAction() == null) {
            launchIntent.setAction(Intent.ACTION_VIEW);
        } else if (launchIntent.getAction().equals(Intent.ACTION_MAIN) &&
                launchIntent.getCategories() != null &&
                launchIntent.getCategories().contains(Intent.CATEGORY_LAUNCHER)) {
            launchIntent.addFlags(
                    Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        }

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

        // Only encode the parameters which are supported by the API.
        JSONStringer json = new JSONStringer()
            .object()
            .key(LAUNCH_INTENT_KEY).value(launchIntent.toUri(0))
            .key(NAME_KEY).value(name);
        if (icon != null) {
            byte[] iconByteArray = Utilities.flattenBitmap(icon);
            json = json.key(ICON_KEY).value(
                    Base64.encodeToString(
                            iconByteArray, 0, iconByteArray.length, Base64.DEFAULT));
        }
        if (iconResource != null) {
            json = json.key(ICON_RESOURCE_NAME_KEY).value(iconResource.resourceName);
            json = json.key(ICON_RESOURCE_PACKAGE_NAME_KEY)
                    .value(iconResource.packageName);
        }
        return json.endObject().toString();
    } catch (JSONException e) {
        e.printStackTrace();
        return null;
    }
}
 
Example 18
Project: Auto.js   File: Shortcut.java   View Source Code Vote up 5 votes
public Intent.ShortcutIconResource getIconRes() {
    return mIconRes;
}
 
Example 19
Project: SimpleUILauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {
        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;
}
 
Example 20
Project: FlickLauncher   File: InstallShortcutReceiver.java   View Source Code Vote up 5 votes
private static PendingInstallShortcutInfo decode(String encoded, Context context) {
    try {
        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;
}