@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 boolean hasHostPermission() { if (AndroidVersion.isAtLeastNougatMR1) { try { return mLauncherApps.hasShortcutHostPermission(); } catch (SecurityException|IllegalStateException e) { e.printStackTrace(); } } return false; } }
@TargetApi(25) public boolean hasHostPermission() { if (Utilities.isNycMR1OrAbove()) { try { return mLauncherApps.hasShortcutHostPermission(); } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to make shortcut manager call", e); } } return false; } }
@TargetApi(25) public boolean hasHostPermission() { if (Utilities.isNycMR1OrAbove()) { try { return mLauncherApps.hasShortcutHostPermission(); } catch (SecurityException|IllegalStateException e) { Log.e(TAG, "Failed to make shortcut manager call", e); } } return false; } }
if (!launcherApps.hasShortcutHostPermission()) { return null;
public static ArrayList<Shortcuts> getRemoteShortcutsOnAPI25(Activity activity, String targetPackageName, int uid) throws Exception { LauncherApps launcherApps = (LauncherApps) activity.getApplicationContext().getSystemService(Context.LAUNCHER_APPS_SERVICE); if (!launcherApps.hasShortcutHostPermission()) { Log.e(TAG, "Don't have permission, you may need set this app as default launcher!"); throw new Exception("Don't have permission, you may need set this app as default launcher!");
final LauncherApps launcherApps = activity.getSystemService(LauncherApps.class); if (launcherApps==null || !launcherApps.hasShortcutHostPermission()) { Toast.makeText(activity, "Must be default launcher", Toast.LENGTH_LONG).show(); return;
final LauncherApps launcherApps = (LauncherApps) mMain.getSystemService(Context.LAUNCHER_APPS_SERVICE); if (launcherApps!=null && launcherApps.hasShortcutHostPermission()) { try {