final Drawable iconDrawable = launcherApps.getShortcutIconDrawable(shortcutInfo, 0); ShortcutsPojo pojo = new ShortcutsPojo(id, shortcutInfo.getPackage(), shortcutInfo.getId(), drawableToBitmap(iconDrawable));
public static Drawable loadDrawable(Context context, ShortcutInfo shortcutInfo) { if (!SDKUtil.AT_LEAST_N_MR1) { return null; } return ((LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE)) .getShortcutIconDrawable(shortcutInfo, context.getResources().getDisplayMetrics().densityDpi); }
@Override public Drawable getFullResIcon(IconCache cache) { return mContext.getSystemService(LauncherApps.class) .getShortcutIconDrawable(mInfo, LauncherAppState.getIDP(mContext).fillResIconDpi); }
@TargetApi(25) public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) { if (AndroidVersion.isAtLeastNougatMR1) { try { Drawable icon = mLauncherApps.getShortcutIconDrawable( shortcutInfo.getShortcutInfo(), density); mWasLastCallSuccess = true; return icon; } catch (SecurityException|IllegalStateException e) { e.printStackTrace(); mWasLastCallSuccess = false; } } return null; }
@TargetApi(25) public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) { if (Utilities.isNycMR1OrAbove()) { try { Drawable icon = mLauncherApps.getShortcutIconDrawable( shortcutInfo.getShortcutInfo(), density); mWasLastCallSuccess = true; return icon; } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to get shortcut icon", e); mWasLastCallSuccess = false; } } return null; }
@TargetApi(25) public Drawable getShortcutIconDrawable(ShortcutInfoCompat shortcutInfo, int density) { if (Utilities.isNycMR1OrAbove()) { try { Drawable icon = mLauncherApps.getShortcutIconDrawable( shortcutInfo.getShortcutInfo(), density); mWasLastCallSuccess = true; return icon; } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to get shortcut icon", e); mWasLastCallSuccess = false; } } return null; }
Drawable shortcutsImage = launcherApps.getShortcutIconDrawable(shortcutInfoList.get(j), metrics.densityDpi); Bitmap shortcutsImageBitmap = Utils.convertDrawableToBitmap(shortcutsImage);
@TargetApi(Build.VERSION_CODES.O) private void acceptShortcut(LauncherApps launcherApps, LauncherApps.PinItemRequest request) { ShortcutReceiver shrecv = GlobState.getShortcutReceiver(this); if (shrecv == null) { return; } ShortcutInfo si = request.getShortcutInfo(); if (si == null) { return; } Drawable iconDrawable = launcherApps.getShortcutIconDrawable(si, 0); Bitmap icon = null; if (iconDrawable != null) { icon = IconsHandler.drawableToBitmap(iconDrawable); } String label = null; if (si.getShortLabel() != null) { label = si.getShortLabel().toString(); CharSequence longlabel = si.getLongLabel(); if (longlabel != null) { if (longlabel.toString().startsWith(label)) { label = longlabel.toString(); } else { label += " " + longlabel; } } } shrecv.addOreoLink(this, si.getId(), si.getPackage(), label, icon); request.accept(); }
private void addShortcutToActionPopup(final LauncherApps launcherApps, final ShortcutInfo shortcutInfo) { if (Build.VERSION.SDK_INT>=25) { if (shortcutInfo != null && shortcutInfo.getActivity() != null) { //Log.d(TAG, shortcutInfo.getShortLabel() + " " + shortcutInfo.getActivity().getClassName()); if (shortcutInfo.isEnabled()) { String label = ""; if (shortcutInfo.getShortLabel() != null) label += shortcutInfo.getShortLabel(); if (shortcutInfo.getLongLabel() != null && !label.contentEquals(shortcutInfo.getLongLabel())) label = shortcutInfo.getLongLabel() + ""; Drawable icon = launcherApps.getShortcutIconDrawable(shortcutInfo, DisplayMetrics.DENSITY_DEFAULT); addActionMenuItem(label.trim(), icon, new Runnable() { @Override public void run() { if (Build.VERSION.SDK_INT >= 25) { try { launcherApps.startShortcut(shortcutInfo, null, null); } catch (Exception e) { Log.e(TAG, "Couldn't Launch shortcut", e); } } dismissActionPopup(); } }); } } } }