@Override public boolean startConfigActivity(Activity activity, int requestCode) { if (getUser().equals(Process.myUserHandle())) { return super.startConfigActivity(activity, requestCode); } try { Method m = LauncherApps.class.getDeclaredMethod( "getShortcutConfigActivityIntent", LauncherActivityInfo.class); IntentSender is = (IntentSender) m.invoke( activity.getSystemService(LauncherApps.class), mInfo); activity.startIntentSenderForResult(is, requestCode, null, 0, 0, 0); return true; } catch (Exception e) { e.printStackTrace(); return false; } }
@TargetApi(Build.VERSION_CODES.N_MR1) private int getLauncherShortcuts() { LauncherApps launcherApps = (LauncherApps) getSystemService(LAUNCHER_APPS_SERVICE); if(launcherApps.hasShortcutHostPermission()) { UserManager userManager = (UserManager) getSystemService(USER_SERVICE); LauncherApps.ShortcutQuery query = new LauncherApps.ShortcutQuery(); query.setActivity(ComponentName.unflattenFromString(componentName)); query.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED); shortcuts = launcherApps.getShortcuts(query, userManager.getUserForSerialNumber(userId)); if(shortcuts != null) return shortcuts.size(); } return 0; }
@Override public List<ShortcutConfigActivityInfo> getCustomShortcutActivityList( @Nullable PackageUserKey packageUser) { List<ShortcutConfigActivityInfo> result = new ArrayList<>(); UserHandle myUser = Process.myUserHandle(); try { Method m = LauncherApps.class.getDeclaredMethod("getShortcutConfigActivityList", String.class, UserHandle.class); final List<UserHandle> users; final String packageName; if (packageUser == null) { users = UserManagerCompat.getInstance(mContext).getUserProfiles(); packageName = null; } else { users = new ArrayList<>(1); users.add(packageUser.mUser); packageName = packageUser.mPackageName; } for (UserHandle user : users) { boolean ignoreTargetSdk = myUser.equals(user); List<LauncherActivityInfo> activities = (List<LauncherActivityInfo>) m.invoke(mLauncherApps, packageName, user); for (LauncherActivityInfo activityInfo : activities) { if (ignoreTargetSdk || activityInfo.getApplicationInfo().targetSdkVersion >= Build.VERSION_CODES.O) { result.add(new ShortcutConfigActivityInfoVO(activityInfo)); } } } } catch (Exception e) { e.printStackTrace(); } return result; }
@SuppressLint("WrongConstant") public static List<ShortcutInfo> loadShortcuts(Context context, String packageName) { if (!SDKUtil.AT_LEAST_N_MR1) { return null; } LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); if (launcherApps == null) { return null; } if (!launcherApps.hasShortcutHostPermission()) { return null; } PackageManager packageManager = context.getPackageManager(); Intent mainIntent = new Intent("android.intent.action.MAIN", null); mainIntent.addCategory("android.intent.category.LAUNCHER"); if (packageManager != null && packageManager.queryIntentActivities(mainIntent, 0) != null) { try { return launcherApps.getShortcuts((new LauncherApps.ShortcutQuery()) .setPackage(packageName).setQueryFlags(QUERY_FLAGS), UserHandle.getUserHandleForUid(context.getPackageManager().getPackageUid(packageName, PackageManager.GET_META_DATA))); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); return null; } } return null; }
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); }
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()); }
private static void launchAndroidForWork(Context context, ComponentName componentName, Bundle bundle, long userId) { UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE); LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); try { launcherApps.startMainActivity(componentName, userManager.getUserForSerialNumber(userId), null, bundle); } catch (ActivityNotFoundException | NullPointerException e) { /* Gracefully fail */ } }
@TargetApi(Build.VERSION_CODES.N_MR1) private static void launchShortcut(Context context, ShortcutInfo shortcut, Bundle bundle) { LauncherApps launcherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); if(launcherApps.hasShortcutHostPermission()) { try { launcherApps.startShortcut(shortcut, null, bundle); } catch (ActivityNotFoundException | NullPointerException e) { /* Gracefully fail */ } } }
LauncherAppsCompatVL(Context context) { mContext = context; mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
private DeepShortcutManager(Context context) { mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
@Override public Drawable getFullResIcon(IconCache cache) { return mContext.getSystemService(LauncherApps.class) .getShortcutIconDrawable(mInfo, LauncherAppState.getIDP(mContext).fillResIconDpi); }
/** * 返回 {@link LauncherApps} */ public static LauncherApps getLauncherApps() { return (LauncherApps) get(LAUNCHER_APPS_SERVICE); }
LauncherAppsCompatVL(Context context) { super(context); mLauncherApps = (LauncherApps) context.getSystemService("launcherapps"); }
DeepShortcutManagerN(Context context) { mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
public DeepShortcutManagerPreN(Context context) { mContext = context; mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); mEnableBackport = true; }
public DeepShortcutManager(Context context, ShortcutCache shortcutCache) { mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
LauncherAppsCompatVL(Context context) { super(); mLauncherApps = (LauncherApps) context.getSystemService("launcherapps"); }
public AppAdapter(Context context) { mInflater = LayoutInflater.from(context); LauncherApps launcherApps = (LauncherApps)getSystemService(Context.LAUNCHER_APPS_SERVICE); mData = launcherApps.getActivityList(null, android.os.Process.myUserHandle()); }
@TargetApi(21) public static LauncherApps getLauncherApps() { return (LauncherApps) getSystemService(Context.LAUNCHER_APPS_SERVICE); }
/** * @since 4.0.0 */ public static LauncherApps launcherApps(Context context) { return (LauncherApps) context.getSystemService(LAUNCHER_APPS_SERVICE); }
LauncherAppsCompatVL(Context context) { super(); mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
public LauncherAppsCompat(final Context context) { mLauncherApps = (LauncherApps) context.getSystemService(Context.LAUNCHER_APPS_SERVICE); }
@TargetApi(AndroidHelper.API_21) public static LauncherApps launcherApps() { return (LauncherApps) get(Context.LAUNCHER_APPS_SERVICE); }
/** * Obtain a {@link LauncherApps} instance associated with specified {@link Context} * * @param context Context * @return {@link LauncherApps} associated with specified {@link Context} * @throws InvalidContextException if {@link LauncherApps} can't be obtained * from specified {@link Context} */ @NonNull @RequiresApi(Build.VERSION_CODES.LOLLIPOP) public static LauncherApps getLauncherApps(@NonNull Context context) { return validate(context.getSystemService(Context.LAUNCHER_APPS_SERVICE)); }