@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(); }
return launcherApps.getShortcuts((new LauncherApps.ShortcutQuery()) .setPackage(packageName).setQueryFlags(QUERY_FLAGS), UserHandle.getUserHandleForUid(context.getPackageManager().getPackageUid(packageName, PackageManager.GET_META_DATA)));
shortcutInfos = mLauncherApps.getShortcuts(q, user); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) {
int queryFlags = LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED; List<ShortcutInfo> shortcutInfoList = launcherApps.getShortcuts( new LauncherApps.ShortcutQuery().setPackage(targetPackageName).setQueryFlags(queryFlags), UserHandle.getUserHandleForUid(uid));
List<ShortcutInfo> shortcuts = launcherApps.getShortcuts(query, userHandle); if (shortcuts != null) { for (ShortcutInfo s: shortcuts) {
shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser()); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) {
shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser()); mWasLastCallSuccess = true; } catch (SecurityException|IllegalStateException e) {
query.setShortcutIds(Collections.singletonList(appitem.getLinkUri())); query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED); List<ShortcutInfo> shortcuts = launcherApps.getShortcuts(query,android.os.Process.myUserHandle()); q.setPackage(appitem.getPackageName()); if (shortcuts!=null && shortcuts.size()>0) { shortcutInfos = launcherApps.getShortcuts(q, android.os.Process.myUserHandle());