List of usage examples for android.content.pm PackageManager getPreferredPackages
public abstract List<PackageInfo> getPreferredPackages(@PackageInfoFlags int flags);
From source file:com.landenlabs.all_devtool.PackageFragment.java
/** * Load packages which are default (associated) with specific mime types. * * Use "adb shell dumpsys package r" to get full list *//*from w ww . j a va2 s. co m*/ void loadDefaultPackages() { m_workList = new ArrayList<PackingItem>(); String[] actions = { Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_SEND, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, Intent.ACTION_VIEW, MediaStore.ACTION_IMAGE_CAPTURE, MediaStore.ACTION_VIDEO_CAPTURE, Intent.ACTION_CREATE_SHORTCUT }; String[] types = { "audio/*", "video/*", "image/*", "text/plain", "application/pdf", "application/zip", "audio/*", "video/*", "image/*", "text/html", "text/plain", "text/csv", "image/png", "video/*", "" }; long orderCnt = 1; for (int idx = 0; idx != actions.length; idx++) { String type = types[idx]; Intent resolveIntent = new Intent(actions[idx]); if (!TextUtils.isEmpty(type)) { if (type.startsWith("audio/*")) { Uri uri = Uri.withAppendedPath(MediaStore.Audio.Media.INTERNAL_CONTENT_URI, "1"); resolveIntent.setDataAndType(uri, type); } else if (type.startsWith("video/*")) { Uri uri = Uri.withAppendedPath(MediaStore.Video.Media.INTERNAL_CONTENT_URI, "1"); resolveIntent.setDataAndType(uri, type); } else if (type.startsWith("text/")) { Uri uri = Uri.parse(Environment.getExternalStorageDirectory().getPath()); resolveIntent.setDataAndType(uri, type); } else { resolveIntent.setType(type); } } PackageManager pm = getActivity().getPackageManager(); // PackageManager.GET_RESOLVED_FILTER); // or PackageManager.MATCH_DEFAULT_ONLY List<ResolveInfo> resolveList = pm.queryIntentActivities(resolveIntent, -1); // PackageManager.MATCH_DEFAULT_ONLY | PackageManager.GET_INTENT_FILTERS); if (resolveList != null) { String actType = type = Utils.last(actions[idx].split("[.]")) + ":" + type; for (ResolveInfo resolveInfo : resolveList) { ArrayListPairString pkgList = new ArrayListPairString(); String appName = resolveInfo.activityInfo.loadLabel(pm).toString().trim(); addList(pkgList, "Type", actType); String pkgName = resolveInfo.activityInfo.packageName; PackageInfo packInfo = null; try { packInfo = pm.getPackageInfo(pkgName, 0); addList(pkgList, "Version", packInfo.versionName); addList(pkgList, "VerCode", String.valueOf(packInfo.versionCode)); addList(pkgList, "TargetSDK", String.valueOf(packInfo.applicationInfo.targetSdkVersion)); m_date.setTime(packInfo.firstInstallTime); addList(pkgList, "Install First", s_timeFormat.format(m_date)); m_date.setTime(packInfo.lastUpdateTime); addList(pkgList, "Install Last", s_timeFormat.format(m_date)); if (resolveInfo.filter != null) { if (resolveInfo.filter.countDataSchemes() > 0) { addList(pkgList, "Intent Scheme", ""); for (int sIdx = 0; sIdx != resolveInfo.filter.countDataSchemes(); sIdx++) addList(pkgList, " ", resolveInfo.filter.getDataScheme(sIdx)); } if (resolveInfo.filter.countActions() > 0) { addList(pkgList, "Intent Action", ""); for (int aIdx = 0; aIdx != resolveInfo.filter.countActions(); aIdx++) addList(pkgList, " ", resolveInfo.filter.getAction(aIdx)); } if (resolveInfo.filter.countCategories() > 0) { addList(pkgList, "Intent Category", ""); for (int cIdx = 0; cIdx != resolveInfo.filter.countCategories(); cIdx++) addList(pkgList, " ", resolveInfo.filter.getCategory(cIdx)); } if (resolveInfo.filter.countDataTypes() > 0) { addList(pkgList, "Intent DataType", ""); for (int dIdx = 0; dIdx != resolveInfo.filter.countDataTypes(); dIdx++) addList(pkgList, " ", resolveInfo.filter.getDataType(dIdx)); } } m_workList.add( new PackingItem(pkgName.trim(), pkgList, packInfo, orderCnt++, appName, actType)); } catch (Exception ex) { } } } if (false) { // TODO - look into this method, see loadCachedPackages int flags = PackageManager.GET_PROVIDERS; List<PackageInfo> packList = pm.getPreferredPackages(flags); if (packList != null) { for (int pkgIdx = 0; pkgIdx < packList.size(); pkgIdx++) { PackageInfo packInfo = packList.get(pkgIdx); // if (((packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) == showSys) { addPackageInfo(packInfo); // } } } } } // getPreferredAppInfo(); /* List<ProviderInfo> providerList = getActivity().getPackageManager().queryContentProviders(null, 0, 0); if (providerList != null) { for (ProviderInfo providerInfo : providerList) { String name = providerInfo.name; String pkg = providerInfo.packageName; } } */ }