public Intent getLaunchIntent(String packageName, int userId) { VPackageManager pm = VPackageManager.get(); Intent intentToResolve = new Intent(Intent.ACTION_MAIN); intentToResolve.addCategory(Intent.CATEGORY_INFO); intentToResolve.setPackage(packageName); List<ResolveInfo> ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId); // Otherwise, try to find a main launcher activity. if (ris == null || ris.size() <= 0) { // reuse the intent instance intentToResolve.removeCategory(Intent.CATEGORY_INFO); intentToResolve.addCategory(Intent.CATEGORY_LAUNCHER); intentToResolve.setPackage(packageName); ris = pm.queryIntentActivities(intentToResolve, intentToResolve.resolveType(context), 0, userId); } if (ris == null || ris.size() <= 0) { return null; } Intent intent = new Intent(intentToResolve); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setClassName(ris.get(0).activityInfo.packageName, ris.get(0).activityInfo.name); return intent; }
/** * 授权 * * @param context * @param intent * @param uri * @param writeAble */ public static void grantPermissions(Context context, Intent intent, Uri uri, boolean writeAble) { int flag = Intent.FLAG_GRANT_READ_URI_PERMISSION; if (writeAble) { flag |= Intent.FLAG_GRANT_WRITE_URI_PERMISSION; } intent.addFlags(flag); List<ResolveInfo> resInfoList = context.getPackageManager() .queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, uri, flag); } }
/** * 从uri中解析出Intent * * @param context 上下文 * @param uri uri * @param flags intentFlags * * @return Intent */ public static Intent getIntentFromUri(Context context, String uri, int flags) { try { Intent intent = Intent.parseUri(uri, flags); if (intent == null) { return null; } List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(intent, 0); if (list == null || list.isEmpty()) { return null; } if (!(context instanceof Activity)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); } return intent; } catch (Throwable e) { DLog.e(e); } return null; }
@Override protected ResolveInfo newResult(VPackage.ActivityIntentInfo info, int match, int userId) { final VPackage.ActivityComponent activity = info.activity; PackageSetting ps = (PackageSetting) activity.owner.mExtras; ActivityInfo ai = PackageParserEx.generateActivityInfo(activity, mFlags, ps.readUserState(userId), userId); if (ai == null) { return null; } final ResolveInfo res = new ResolveInfo(); res.activityInfo = ai; if ((mFlags & PackageManager.GET_RESOLVED_FILTER) != 0) { res.filter = info.filter; } res.priority = info.filter.getPriority(); res.preferredOrder = activity.owner.mPreferredOrder; res.match = match; res.isDefault = info.hasDefault; res.labelRes = info.labelRes; res.nonLocalizedLabel = info.nonLocalizedLabel; res.icon = info.icon; return res; }
/** * Resolves the {@link ComponentName components} for all providers which can handle the * specified OpenYOLO action. */ @NonNull public static List<ComponentName> findProviders( @NonNull Context applicationContext, @NonNull String action) { Intent providerIntent = new Intent(action); providerIntent.addCategory(OPENYOLO_CATEGORY); List<ResolveInfo> resolveInfos = applicationContext.getPackageManager() .queryIntentActivities(providerIntent, 0); ArrayList<ComponentName> responders = new ArrayList<>(); for (ResolveInfo info : resolveInfos) { responders.add(new ComponentName( info.activityInfo.packageName, info.activityInfo.name)); } return responders; }
public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType, int flags, ArrayList<PackageParser.Service> packageServices) { if (packageServices == null) { return null; } mFlags = flags; final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0; final int N = packageServices.size(); ArrayList<PackageParser.ServiceIntentInfo[]> listCut = new ArrayList<PackageParser.ServiceIntentInfo[]>(N); ArrayList<PackageParser.ServiceIntentInfo> intentFilters; for (int i = 0; i < N; ++i) { intentFilters = packageServices.get(i).intents; if (intentFilters != null && intentFilters.size() > 0) { PackageParser.ServiceIntentInfo[] array = new PackageParser.ServiceIntentInfo[intentFilters.size()]; intentFilters.toArray(array); listCut.add(array); } } return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut); }
public List<ResolveInfo> queryIntentForPackage(Intent intent, String resolvedType, int flags, ArrayList<VPackage.ProviderComponent> packageProviders, int userId) { if (packageProviders == null) { return null; } mFlags = flags; final boolean defaultOnly = (flags & PackageManager.MATCH_DEFAULT_ONLY) != 0; final int N = packageProviders.size(); ArrayList<VPackage.ProviderIntentInfo[]> listCut = new ArrayList<>(N); ArrayList<VPackage.ProviderIntentInfo> intentFilters; for (int i = 0; i < N; ++i) { intentFilters = packageProviders.get(i).intents; if (intentFilters != null && intentFilters.size() > 0) { VPackage.ProviderIntentInfo[] array = new VPackage.ProviderIntentInfo[intentFilters .size()]; intentFilters.toArray(array); listCut.add(array); } } return super.queryIntentFromList(intent, resolvedType, defaultOnly, listCut, userId); }
public static String getCurLauncher(Context context) { if (context == null) { return null; } try { Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_HOME); ResolveInfo resolveInfo = context.getPackageManager().resolveActivity(mainIntent, 0); if (resolveInfo != null) { return resolveInfo.activityInfo.packageName; } } catch (Exception e) { e.printStackTrace(); } return null; }
@Override public List<ResolveInfo> queryIntentServices(Intent intent, String resolvedType, int flags) throws RemoteException { waitForReadyInner(); try { enforcePluginFileExists(); if (shouldNotBlockOtherInfo()) { return IntentMatcher.resolveServiceIntent(mContext, mPluginCache, intent, resolvedType, flags); } else { List<String> pkgs = mActivityManagerService.getPackageNamesByPid(Binder.getCallingPid()); List<ResolveInfo> infos = new ArrayList<ResolveInfo>(); for (String pkg : pkgs) { intent.setPackage(pkg); List<ResolveInfo> list = IntentMatcher.resolveServiceIntent(mContext, mPluginCache, intent, resolvedType, flags); infos.addAll(list); } if (infos != null && infos.size() > 0) { return infos; } } } catch (Exception e) { handleException(e); } return null; }
/** * This is used to check whether GSA package is available to handle search requests and if * the Chrome experiment to do so is enabled. * @return Whether the search intent this class creates will resolve to an activity. */ public boolean isGsaAvailable() { if (mGsaAvailable != null) return mGsaAvailable; mGsaAvailable = false; PackageManager pm = mContext.getPackageManager(); Intent searchIntent = new Intent(SEARCH_INTENT_ACTION); searchIntent.setPackage(GSAState.SEARCH_INTENT_PACKAGE); List<ResolveInfo> resolveInfo = pm.queryIntentActivities(searchIntent, 0); if (resolveInfo.size() == 0) { mGsaAvailable = false; } else if (!isPackageAboveVersion(SEARCH_INTENT_PACKAGE, GSA_VERSION_FOR_DOCUMENT) || !isPackageAboveVersion(GMS_CORE_PACKAGE, GMS_CORE_VERSION)) { mGsaAvailable = false; } else { mGsaAvailable = true; } return mGsaAvailable; }
static Pair<String, Resources> findSystemApk(String action, PackageManager pm) { final Intent intent = new Intent(action); for (ResolveInfo info : pm.queryBroadcastReceivers(intent, 0)) { if (info.activityInfo != null && (info.activityInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { final String packageName = info.activityInfo.packageName; try { final Resources res = pm.getResourcesForApplication(packageName); return Pair.create(packageName, res); } catch (NameNotFoundException e) { Log.w(TAG, "Failed to find resources for " + packageName); } } } return null; }
@Test public void testQueryActionViewIntentActivities() throws Exception { File txt = new File("/test.txt"); Uri uri = Uri.fromFile(txt); // 获取扩展名 String extension = MimeTypeMap.getFileExtensionFromUrl(uri.toString()); // 获取MimeType String mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension); // 创建隐式Intent Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(uri, mimeType); Context context = InstrumentationRegistry.getContext(); PackageManager packageManager = context.getPackageManager(); // 根据Intent查询匹配的Activity列表 List<ResolveInfo> resolvers = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolver : resolvers) { Log.d(TAG, resolver.activityInfo.packageName + "\n" + resolver.activityInfo.name); } }
public void dispatchCaptureIntent(Context context, int requestCode) { Intent captureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (captureIntent.resolveActivity(context.getPackageManager()) != null) { File photoFile = null; try { photoFile = createImageFile(); } catch (IOException e) { e.printStackTrace(); } if (photoFile != null) { mCurrentPhotoPath = photoFile.getAbsolutePath(); mCurrentPhotoUri = FileProvider.getUriForFile(mContext.get(), mCaptureStrategy.authority, photoFile); captureIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCurrentPhotoUri); captureIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION); if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { List<ResolveInfo> resInfoList = context.getPackageManager() .queryIntentActivities(captureIntent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo resolveInfo : resInfoList) { String packageName = resolveInfo.activityInfo.packageName; context.grantUriPermission(packageName, mCurrentPhotoUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION); } } if (mFragment != null) { mFragment.get().startActivityForResult(captureIntent, requestCode); } else { mContext.get().startActivityForResult(captureIntent, requestCode); } } } }
private boolean validateAppSignatureForIntent(Context context, Intent intent) { PackageManager pm = context.getPackageManager(); ResolveInfo resolveInfo = pm.resolveActivity(intent, 0); if (resolveInfo == null) { return false; } try { for (Signature signature : pm.getPackageInfo(resolveInfo.activityInfo.packageName, 64).signatures) { if (WEIBO_SIGNATURE.equals(signature.toCharsString())) { return true; } } return false; } catch (NameNotFoundException e) { return false; } }
/** * Crappy async implementation * * @param info the app to load the icon for * @param callback an interface to pass the adaptive icon to, or null if it cannot be obtained * @return the started thread */ public Thread loadAsync(final ResolveInfo info, final AsyncCallback callback) { Thread thread = new Thread() { @Override public void run() { final AdaptiveIcon icon = load(info); new Handler(Looper.getMainLooper()).post(new Runnable() { @Override public void run() { callback.onResult(info, icon); } }); } }; thread.start(); return thread; }
public int compare(ResolveInfo r1, ResolveInfo r2) { int v1 = r1.priority; int v2 = r2.priority; if (v1 != v2) { return (v1 > v2) ? -1 : 1; } v1 = r1.preferredOrder; v2 = r2.preferredOrder; if (v1 != v2) { return (v1 > v2) ? -1 : 1; } if (r1.isDefault != r2.isDefault) { return r1.isDefault ? -1 : 1; } v1 = r1.match; v2 = r2.match; if (v1 != v2) { return (v1 > v2) ? -1 : 1; } return 0; }
@Test public void open_launchesActivityWithUrl() { Context context = mock(Context.class); when(context.getPackageName()).thenReturn("com.braintreepayments.popupbridge"); PackageManager packageManager = mock(PackageManager.class); when(packageManager.queryIntentActivities(any(Intent.class), anyInt())) .thenReturn(Collections.singletonList(new ResolveInfo())); when(context.getPackageManager()).thenReturn(packageManager); mActivity = spy(Robolectric.setupActivity(TestActivity.class)); when(mActivity.getApplicationContext()).thenReturn(context); mWebView = new MockWebView(mActivity); mPopupBridge = PopupBridge.newInstance(mActivity, mWebView); mPopupBridge.open("someUrl://"); ArgumentCaptor<Intent> captor = ArgumentCaptor.forClass(Intent.class); verify(context).startActivity(captor.capture()); Uri intentUri = captor.getValue().getData(); assertEquals(intentUri.toString(), "someUrl://"); }
/** * 获取正在运行桌面包名 */ public static String getLauncherPackageName(Context context) { final Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); final ResolveInfo res = context.getPackageManager().resolveActivity(intent, 0); return res.activityInfo.packageName; }
@Override protected void convert(ViewHolder holder, final ResolveInfo resolveInfo, int position) { holder.setImageDrawable(R.id.image_view_resolver_icon, resolveInfo.loadIcon(mPackageManager)); holder.setText(R.id.text_view_resolve_display_name, resolveInfo.loadLabel(mPackageManager).toString()); holder.getConvertView().setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mOnResolveInfoListener != null) { mOnResolveInfoListener.onResolveInfoClick(resolveInfo); } } }); }
@Override public ResolveInfo resolveService(final Intent intent, final int flags) { final int original_intent_flags = intent.getFlags(); // Intent flags could only filter background receivers, we have to deal with services by ourselves. return mCondom.proceed(OutboundType.QUERY_SERVICES, intent, null, new CondomCore.WrappedValueProcedure<ResolveInfo>() { @Override public ResolveInfo proceed() { if (! mCondom.mExcludeBackgroundServices && mCondom.mOutboundJudge == null) return CondomPackageManager.super.resolveService(intent, flags); // Shortcut for pass-through final List<ResolveInfo> candidates = CondomPackageManager.super.queryIntentServices(intent, flags); final Intent original_intent = intent.setFlags(original_intent_flags); // Restore the intent flags early before getFirstMatch(). return mCondom.filterCandidates(OutboundType.QUERY_SERVICES, original_intent, candidates, TAG, false); }}); }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { boolean slice = ParceledListSliceCompat.isReturnParceledListSlice(method); int userId = VUserHandle.myUserId(); List<ResolveInfo> appResult = VPackageManager.get().queryIntentReceivers((Intent) args[0], (String) args[1], (Integer) args[2], userId); Object _hostResult = method.invoke(who, args); List<ResolveInfo> hostResult = slice ? ParceledListSlice.getList.call(_hostResult) : (List) _hostResult; Iterator<ResolveInfo> iterator = hostResult.iterator(); while (iterator.hasNext()) { ResolveInfo info = iterator.next(); if (info == null || info.activityInfo == null || !isVisiblePackage(info.activityInfo.applicationInfo)) { iterator.remove(); } } appResult.addAll(hostResult); if (slice) { return ParceledListSliceCompat.create(appResult); } return appResult; }
/** * Retrieve outgoing call handlers available as plugin for csipsimple Also * contains stock call handler if available * * @param ctxt context of application * @return A map of package name => Fancy name of call handler */ public static Map<String, String> getAvailableCallHandlers(Context ctxt) { if (AVAILABLE_HANDLERS == null) { AVAILABLE_HANDLERS = new HashMap<String, String>(); PackageManager packageManager = ctxt.getPackageManager(); Intent it = new Intent(SipManager.ACTION_GET_PHONE_HANDLERS); List<ResolveInfo> availables = packageManager.queryBroadcastReceivers(it, 0); for (ResolveInfo resInfo : availables) { ActivityInfo actInfos = resInfo.activityInfo; Log.d(THIS_FILE, "Found call handler " + actInfos.packageName + " " + actInfos.name); if (packageManager.checkPermission(permission.PROCESS_OUTGOING_CALLS, actInfos.packageName) == PackageManager.PERMISSION_GRANTED) { String packagedActivityName = (new ComponentName(actInfos.packageName, actInfos.name)).flattenToString(); AVAILABLE_HANDLERS.put(packagedActivityName, (String) resInfo.loadLabel(packageManager)); } } } return AVAILABLE_HANDLERS; }
/** * Resolve the default external handler of an intent. * @return Whether the default external handler is found: if chrome turns out to be the * default handler, this method will return false. */ private boolean hasDefaultHandler(Intent intent) { try { ResolveInfo info = mApplicationContext.getPackageManager().resolveActivity(intent, 0); if (info != null) { final String chromePackage = mApplicationContext.getPackageName(); // If a default handler is found and it is not chrome itself, fire the intent. if (info.match != 0 && !chromePackage.equals(info.activityInfo.packageName)) { return true; } } } catch (RuntimeException e) { IntentUtils.logTransactionTooLargeOrRethrow(e, intent); } return false; }
@Override public Object call(Object who, Method method, Object... args) throws Throwable { boolean slice = ParceledListSliceCompat.isReturnParceledListSlice(method); int userId = VUserHandle.myUserId(); List<ResolveInfo> appResult = VPackageManager.get().queryIntentActivities((Intent) args[0], (String) args[1], (Integer) args[2], userId); Object _hostResult = method.invoke(who, args); List<ResolveInfo> hostResult = slice ? ParceledListSlice.getList.call(_hostResult) : (List) _hostResult; Iterator<ResolveInfo> iterator = hostResult.iterator(); while (iterator.hasNext()) { ResolveInfo info = iterator.next(); if (info == null || info.activityInfo == null || !isVisiblePackage(info.activityInfo.applicationInfo)) { iterator.remove(); } } appResult.addAll(hostResult); if (slice) { return ParceledListSliceCompat.create(appResult); } return appResult; }
@Override public List<ResolveInfo> queryIntentActivities(Intent intent, String resolvedType, int flags, int userId) { checkUserId(userId); ComponentName comp = intent.getComponent(); if (comp == null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { if (intent.getSelector() != null) { intent = intent.getSelector(); comp = intent.getComponent(); } } } if (comp != null) { final List<ResolveInfo> list = new ArrayList<ResolveInfo>(1); final ActivityInfo ai = getActivityInfo(comp, flags, userId); if (ai != null) { final ResolveInfo ri = new ResolveInfo(); ri.activityInfo = ai; list.add(ri); } return list; } // reader synchronized (mPackages) { final String pkgName = intent.getPackage(); if (pkgName == null) { return mActivities.queryIntent(intent, resolvedType, flags); } final PackageParser.Package pkg = mPackages.get(pkgName); if (pkg != null) { return mActivities.queryIntentForPackage(intent, resolvedType, flags, pkg.activities); } return new ArrayList<ResolveInfo>(); } }
/** * Used to check whether there is a specialized handler for a given intent. * @param intent The intent to check with. * @return Whether there is a specialized handler for the given intent. */ private static boolean hasSpecializedHandlerIntents(Context context, Intent intent) { try { PackageManager pm = context.getPackageManager(); List<ResolveInfo> handlers = pm.queryIntentActivities( intent, PackageManager.GET_RESOLVED_FILTER); if (handlers == null || handlers.size() == 0) { return false; } for (ResolveInfo resolveInfo : handlers) { IntentFilter filter = resolveInfo.filter; if (filter == null) continue; if (filter.countDataAuthorities() == 0 || filter.countDataPaths() == 0) continue; if (resolveInfo.activityInfo == null) continue; return true; } } catch (RuntimeException ignored) { Log.e(TAG, "Runtime exception while getting specialized handlers"); } return false; }
public List<ResolveInfo> getShareApps(Context context) { List<ResolveInfo> mApps = new ArrayList<ResolveInfo>(); Intent intent = new Intent(Intent.ACTION_SEND, null); intent.addCategory(Intent.CATEGORY_DEFAULT); intent.setType("text/plain"); // intent.setType("*/*"); PackageManager pManager = context.getPackageManager(); mApps = pManager.queryIntentActivities(intent, PackageManager.COMPONENT_ENABLED_STATE_DEFAULT); return mApps; }
private <T extends ComponentInfo> ResolveInfo queryIntentResolveInfo(Intent intent,Class<T> infoClass ){ if(intent==null){ return null; } AdditionalComponentIntentResolver resolver = null; if(infoClass == ActivityInfo.class){ resolver = mExternalActivity; }else{ resolver = mExternalServices; } if(resolver!=null) { ComponentName comp = intent.getComponent(); if (comp == null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { if (intent.getSelector() != null) { intent = intent.getSelector(); comp = intent.getComponent(); } } } if (comp != null) { Object obj = resolver.mComponents.get(comp); if (obj!=null){ try { final ResolveInfo ri = new ExternalResolverInfo(); if(resolver == mExternalActivity) { ri.activityInfo = (ActivityInfo) obj.getClass().getField("info").get(obj); }else{ ri.serviceInfo = (ServiceInfo) obj.getClass().getField("info").get(obj); } return ri; }catch(Exception e){ return null; } }else{ return null; } }else{ // 先检测包名 if (!TextUtils.isEmpty(intent.getPackage()) && !TextUtils.equals(intent.getPackage(), RuntimeVariables.androidApplication.getPackageName())) { return null; } List<ResolveInfo> list = resolver.queryIntent(intent, intent.resolveTypeIfNeeded(RuntimeVariables.androidApplication.getContentResolver()), false); if(list!=null && list.size()>0){ return new ExternalResolverInfo(list.get(0)); }else{ return null; } } }else{ return null; } }
/** * 获得属于桌面的应用的应用包名称 * * @return 返回包含所有包名的字符串列表 */ private static List<String> getHomes(Context context) { List<String> names = new ArrayList<String>(); PackageManager packageManager = context.getPackageManager(); Intent intent = new Intent(Intent.ACTION_MAIN); intent.addCategory(Intent.CATEGORY_HOME); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); for (ResolveInfo ri : resolveInfo) { names.add(ri.activityInfo.packageName); } return names; }
private Object startService(Object proxy, Method method, Object[] args) throws Throwable { IApplicationThread appThread = (IApplicationThread) args[0]; Intent target = (Intent) args[1]; ResolveInfo resolveInfo = this.mPluginManager.resolveService(target, 0); if (null == resolveInfo || null == resolveInfo.serviceInfo) { // is host service return method.invoke(this.mActivityManager, args); } return startDelegateServiceForTarget(target, resolveInfo.serviceInfo, null, RemoteService.EXTRA_COMMAND_START_SERVICE); }
public List<LauncherActivityInfoCompat> getActivityList(String packageName, UserHandleCompat user) { final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mainIntent.setPackage(packageName); List<ResolveInfo> infos = mPm.queryIntentActivities(mainIntent, 0); List<LauncherActivityInfoCompat> list = new ArrayList<LauncherActivityInfoCompat>(infos.size()); for (ResolveInfo info : infos) { list.add(new LauncherActivityInfoCompatV16(mContext, info)); } return list; }
public AppItem(String appName, ResolveInfo ri) { mAppName = appName; mResolveInfo = ri; if (mResolveInfo != null) { mIntent = new Intent(Intent.ACTION_MAIN); mIntent.addCategory(Intent.CATEGORY_LAUNCHER); ComponentName cn = new ComponentName(mResolveInfo.activityInfo.packageName, mResolveInfo.activityInfo.name); mIntent.setComponent(cn); mIntent.putExtra("mode", MODE_APP); if (mForceCustomIcon) { mIntent.putExtra("iconResName", "ic_shortcut_help"); } } }
public List<ShareItem> getShareables() { final Intent shareIntent = createShareIntent(null, "dummy message"); final List<ResolveInfo> infos = context.getPackageManager().queryIntentActivities(shareIntent, 0); final List<ShareItem> result = new ArrayList<>(userShareItems.size() + infos.size()); result.addAll(userShareItems); result.addAll(createSystemShareItems(infos)); return result; }
@TargetApi(VERSION_CODES.KITKAT) private static ResolveInfo newResolveInfo(ProviderInfo providerInfo, IntentFilter intentFilter) { ResolveInfo resolveInfo = new ResolveInfo(); resolveInfo.providerInfo = providerInfo; resolveInfo.filter = intentFilter; resolveInfo.resolvePackageName = providerInfo.packageName; resolveInfo.labelRes = providerInfo.labelRes; resolveInfo.icon = providerInfo.icon; resolveInfo.specificIndex = 1; // 默认就是false,不用再设置了。 // resolveInfo.system = false; resolveInfo.priority = intentFilter.getPriority(); resolveInfo.preferredOrder = 0; return resolveInfo; }
/** * Called to get the best specific destination. * <p> * <b>only use for condition not mAllowLeaving.</b> * <b>only same or similar package name will return.</b> * ResolveInfo's priority was highest, * if priority equal, same package return. * <b>we asume the packagename is xxx.xxx.xxx style.</b> */ private ResolveInfo optimum(final List<ResolveInfo> list) { if (list == null) return null; else if (list.size() == 1) { return list.get(0); } final ArrayList<SortedResolveInfo> resolveInfo = new ArrayList<SortedResolveInfo>(); for (final ResolveInfo info : list) { if (!TextUtils.isEmpty(info.activityInfo.packageName)) { if (info.activityInfo.packageName.endsWith(mContext.getPackageName())) { resolveInfo.add(new SortedResolveInfo(info, info.priority, 1)); } else { final String p1 = info.activityInfo.packageName; final String p2 = mContext.getPackageName(); final String[] l1 = p1.split("\\."); final String[] l2 = p2.split("\\."); if (l1.length >= 2 && l2.length >= 2) { if (l1[0].equals(l2[0]) && l1[1].equals(l2[1])) resolveInfo.add(new SortedResolveInfo(info, info.priority, 0)); } } } } if (resolveInfo.size() > 0) { if (resolveInfo.size() > 1) { Collections.sort(resolveInfo); } final ResolveInfo ret = resolveInfo.get(0).info; resolveInfo.clear(); return ret; } else { return null; } }
private ActivityInfo getActivity(final CallbackContext callbackContext, final Intent shareIntent, final String appPackageName, final String appName) { final PackageManager pm = webView.getContext().getPackageManager(); List<ResolveInfo> activityList = pm.queryIntentActivities(shareIntent, 0); for (final ResolveInfo app : activityList) { if ((app.activityInfo.packageName).contains(appPackageName)) { if (appName == null || (app.activityInfo.name).contains(appName)) { return app.activityInfo; } } } // no matching app found callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, getShareActivities(activityList))); return null; }
public HashMap<String, IconPack> getAvailableIconPacks(boolean forceReload) { if (iconPacks == null || forceReload) { iconPacks = new HashMap<String, IconPack>(); // find apps with intent-filter "com.gau.go.launcherex.theme" and return build the HashMap PackageManager pm = mContext.getPackageManager(); List<ResolveInfo> adwlauncherthemes = pm.queryIntentActivities(new Intent("org.adw.launcher.THEMES"), PackageManager.GET_META_DATA); List<ResolveInfo> golauncherthemes = pm.queryIntentActivities(new Intent("com.gau.go.launcherex.theme"), PackageManager.GET_META_DATA); // merge those lists List<ResolveInfo> rinfo = new ArrayList<ResolveInfo>(adwlauncherthemes); rinfo.addAll(golauncherthemes); for(ResolveInfo ri : rinfo) { IconPack ip = new IconPack(); ip.packageName = ri.activityInfo.packageName; ApplicationInfo ai = null; try { ai = pm.getApplicationInfo(ip.packageName, PackageManager.GET_META_DATA); ip.name = mContext.getPackageManager().getApplicationLabel(ai).toString(); iconPacks.put(ip.packageName, ip); } catch (PackageManager.NameNotFoundException e) { // shouldn't happen e.printStackTrace(); } } } return iconPacks; }
@Override public ResolveInfo resolveService(Intent intent, String resolvedType, int flags, int userId) { checkUserId(userId); flags = updateFlagsNought(flags); List<ResolveInfo> query = queryIntentServices(intent, resolvedType, flags, userId); if (query != null) { if (query.size() >= 1) { // If there is more than one service with the same priority, // just arbitrarily pick the first one. return query.get(0); } } return null; }
public static List<ResolveInfo> findActivitiesForPackage(Context context, String packageName) { final PackageManager packageManager = context.getPackageManager(); final Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); mainIntent.setPackage(packageName); final List<ResolveInfo> apps = packageManager.queryIntentActivities(mainIntent, 0); return apps != null ? apps : new ArrayList<ResolveInfo>(); }