@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(); }
@TargetApi(25) public void startShortcut(String packageName, String id, Rect sourceBounds, Bundle startActivityOptions, UserHandle user) { if (AndroidVersion.isAtLeastNougatMR1) { try { mLauncherApps.startShortcut(packageName, id, sourceBounds, startActivityOptions, user); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) { e.printStackTrace(); mWasLastCallSuccess = false; } } }
public static void launchShortcut(View view, ShortcutInfo shortcutInfo) { if (!SDKUtil.AT_LEAST_N_MR1) { return; } ((LauncherApps) view.getContext().getSystemService(Context.LAUNCHER_APPS_SERVICE)) .startShortcut(shortcutInfo, IntentUtil.getViewBounds(view), new Bundle()); } }
@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(); } });
@TargetApi(25) public void startShortcut(String packageName, String id, Rect sourceBounds, Bundle startActivityOptions, UserHandleCompat user) { if (Utilities.isNycMR1OrAbove()) { try { mLauncherApps.startShortcut(packageName, id, sourceBounds, startActivityOptions, user.getUser()); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to start shortcut", e); mWasLastCallSuccess = false; } } }
@TargetApi(25) public void startShortcut(String packageName, String id, Rect sourceBounds, Bundle startActivityOptions, UserHandleCompat user) { if (Utilities.isNycMR1OrAbove()) { try { mLauncherApps.startShortcut(packageName, id, sourceBounds, startActivityOptions, user.getUser()); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to start shortcut", e); mWasLastCallSuccess = false; } } }
for (ShortcutInfo s: shortcuts) { if (s!=null && s.isEnabled()) { launcherApps.startShortcut(s, null, null); return; } else {