@TargetApi(Build.VERSION_CODES.O) private void doOreoLaunch(Context context, View v) { final LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); assert launcherApps != null; // Only the default launcher is allowed to start shortcuts if (!launcherApps.hasShortcutHostPermission()) { Toast.makeText(context, context.getString(R.string.shortcuts_no_host_permission), Toast.LENGTH_LONG).show(); return; } LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery(); query.setPackage(shortcutPojo.packageName); query.setShortcutIds(Collections.singletonList(shortcutPojo.getOreoId())); query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED); List<UserHandle> userHandles = launcherApps.getProfiles(); // Find the correct UserHandle, and launch the shortcut. for (UserHandle userHandle : userHandles) { List<ShortcutInfo> shortcuts = launcherApps.getShortcuts(query, userHandle); if (shortcuts != null && shortcuts.size() > 0 && shortcuts.get(0).isEnabled()) { launcherApps.startShortcut(shortcuts.get(0), v.getClipBounds(), null); return; } } // Application removed? Invalid shortcut? Shortcut to an app on an unmounted SD card? Toast.makeText(context, R.string.application_not_found, Toast.LENGTH_LONG).show(); }
public boolean isEnabled() { return mShortcutInfo.isEnabled(); }
public boolean isEnabled() { return mShortcutInfo.isEnabled(); }
public boolean isEnabled() { return mShortcutInfo.isEnabled(); }
if (shortcuts != null) { for (ShortcutInfo s: shortcuts) { if (s!=null && s.isEnabled()) { launcherApps.startShortcut(s, null, null); return;
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(); } }); } } } }