List of usage examples for android.content.pm PackageManager MATCH_UNINSTALLED_PACKAGES
int MATCH_UNINSTALLED_PACKAGES
To view the source code for android.content.pm PackageManager MATCH_UNINSTALLED_PACKAGES.
Click Source Link
From source file:org.deviceconnect.android.observer.fragment.WarningDialogFragment.java
/** * ????.//from w ww . j av a 2 s . c o m * * @param packageName ??? * @return ?? */ private String getAppName(final String packageName) { PackageManager pm = getActivity().getPackageManager(); final List<ApplicationInfo> appInfoList = pm.getInstalledApplications( PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS); for (ApplicationInfo ai : appInfoList) { String appName = ai.loadLabel(pm).toString(); if (ai.packageName.equals(packageName)) { return appName; } } return "NoName"; }
From source file:com.android.tv.settings.users.AppRestrictionsFragment.java
private void populateApps() { final Context context = getActivity(); if (context == null) return;/*from ww w .j av a 2s. c o m*/ final PackageManager pm = mPackageManager; final int userId = mUser.getIdentifier(); // Check if the user was removed in the meantime. if (getExistingUser(mUserManager, mUser) == null) { return; } mAppList.removeAll(); addLocationAppRestrictionsPreference(); Intent restrictionsIntent = new Intent(Intent.ACTION_GET_RESTRICTION_ENTRIES); final List<ResolveInfo> receivers = pm.queryBroadcastReceivers(restrictionsIntent, 0); for (AppRestrictionsHelper.SelectableAppInfo app : mHelper.getVisibleApps()) { String packageName = app.packageName; if (packageName == null) continue; final boolean isSettingsApp = packageName.equals(context.getPackageName()); AppRestrictionsPreference p = new AppRestrictionsPreference(getPreferenceManager().getContext()); final boolean hasSettings = resolveInfoListHasPackage(receivers, packageName); if (isSettingsApp) { // Settings app should be available to restricted user mHelper.setPackageSelected(packageName, true); continue; } PackageInfo pi = null; try { pi = mIPm.getPackageInfo(packageName, PackageManager.MATCH_UNINSTALLED_PACKAGES | PackageManager.GET_SIGNATURES, userId); } catch (RemoteException e) { // Ignore } if (pi == null) { continue; } if (mRestrictedProfile && isAppUnsupportedInRestrictedProfile(pi)) { continue; } p.setIcon(app.icon != null ? app.icon.mutate() : null); p.setChecked(false); p.setTitle(app.activityName); p.setKey(getKeyForPackage(packageName)); p.setPersistent(false); p.setOnPreferenceChangeListener(this); p.setSummary(getPackageSummary(pi, app)); if (pi.requiredForAllUsers || isPlatformSigned(pi)) { p.setChecked(true); p.setImmutable(true); // If the app is required and has no restrictions, skip showing it if (!hasSettings) continue; } else if (!mNewUser && isAppEnabledForUser(pi)) { p.setChecked(true); } if (app.masterEntry == null && hasSettings) { requestRestrictionsForApp(packageName, p); } if (app.masterEntry != null) { p.setImmutable(true); p.setChecked(mHelper.isPackageSelected(packageName)); } p.setOrder(MAX_APP_RESTRICTIONS * (mAppList.getPreferenceCount() + 2)); mHelper.setPackageSelected(packageName, p.isChecked()); mAppList.addPreference(p); } mAppListChanged = true; // If this is the first time for a new profile, install/uninstall default apps for profile // to avoid taking the hit in onPause(), which can cause race conditions on user switch. if (mNewUser && mFirstTime) { mFirstTime = false; mHelper.applyUserAppsStates(this); } }