Example usage for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES

List of usage examples for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES

Introduction

In this page you can find the example usage for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES.

Prototype

int GET_UNINSTALLED_PACKAGES

To view the source code for android.content.pm PackageManager GET_UNINSTALLED_PACKAGES.

Click Source Link

Usage

From source file:com.oasisfeng.nevo.decorators.bundle.BundleDecorator.java

private String getSourceNames(final Set<String> pkgs) {
    final PackageManager pm = getPackageManager();
    final StringBuilder names = new StringBuilder();
    for (final String pkg : pkgs)
        try {//  w  ww .  j  av  a 2 s. c  om
            final ApplicationInfo app_info = pm.getApplicationInfo(pkg,
                    PackageManager.GET_UNINSTALLED_PACKAGES);
            names.append(", ").append(app_info.loadLabel(pm));
        } catch (final NameNotFoundException ignored) {
        } // TODO: Packages from other user profiles?
    return names.substring(2);
}

From source file:org.wso2.iot.agent.api.ApplicationManager.java

/**
 * Return the list of the package names of the apps(hidden and visible) that are user owned
 *
 * @return - list of package names of the apps that are not system apps
 *//* www  .  ja v  a  2  s .c  o  m*/
public List<String> getAppsOfUser() {
    List<String> packagesInstalledByUser = new ArrayList<>();
    int flags = PackageManager.GET_META_DATA | PackageManager.GET_SHARED_LIBRARY_FILES
            | PackageManager.GET_UNINSTALLED_PACKAGES;
    List<ApplicationInfo> applications = packageManager.getInstalledApplications(flags);
    for (ApplicationInfo appInfo : applications) {
        if (!((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 1)) {
            packagesInstalledByUser.add(appInfo.packageName);
        }
    }
    return packagesInstalledByUser;
}

From source file:com.polyvi.xface.extension.XAppExt.java

/**
 * ???/*www  .  j av  a 2  s  .c o m*/
 *
 * @param appId
 *            ?id??
 * @return true??
 */
public boolean isAppInstalled(String appId) {
    if (null == appId) {
        return false;
    }

    try {
        getContext().getPackageManager().getApplicationInfo(appId, PackageManager.GET_UNINSTALLED_PACKAGES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:org.deviceconnect.android.manager.setting.DevicePluginInfoFragment.java

/**
 * Tests whether packageName exists in application list.
 *
 * @param packageName package name//from  ww  w .  j  a  va  2s . co m
 * @return true if packageName exists, false otherwise
 */
private boolean existApplicationFromPackageName(final String packageName) {
    if (packageName == null) {
        return false;
    }

    final PackageManager pm = getActivity().getPackageManager();
    final int flags = PackageManager.GET_UNINSTALLED_PACKAGES | PackageManager.MATCH_DISABLED_COMPONENTS;
    final List<ApplicationInfo> installedAppList = pm.getInstalledApplications(flags);
    for (ApplicationInfo app : installedAppList) {
        if (app.packageName.equals(packageName)) {
            return true;
        }
    }
    return false;
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void initiateInstall() {
    String pkgName = mPkgInfo.packageName;
    // Check if there is already a package on the device with this name
    // but it has been renamed to something else.
    String[] oldName = mPm.canonicalToCurrentPackageNames(new String[] { pkgName });
    if (oldName != null && oldName.length > 0 && oldName[0] != null) {
        pkgName = oldName[0];/*  w  w w.j av a2  s.co  m*/
        mPkgInfo.packageName = pkgName;
        mPkgInfo.applicationInfo.packageName = pkgName;
    }
    // Check if package is already installed. display confirmation dialog if replacing pkg
    try {
        // This is a little convoluted because we want to get all uninstalled
        // apps, but this may include apps with just data, and if it is just
        // data we still want to count it as "installed".
        mAppInfo = mPm.getApplicationInfo(pkgName, PackageManager.GET_UNINSTALLED_PACKAGES);
        if ((mAppInfo.flags & ApplicationInfo.FLAG_INSTALLED) == 0) {
            mAppInfo = null;
        }
    } catch (NameNotFoundException e) {
        mAppInfo = null;
    }

    startInstallConfirm();
}

From source file:android.content.pm.PackageParser.java

/**
 * Returns true if the package is installed and not hidden, or if the caller
 * explicitly wanted all uninstalled and hidden packages as well.
 *///from  ww  w.  ja  v  a  2  s  .co  m
private static boolean checkUseInstalledOrHidden(int flags, PackageUserState state) {
    return (state.installed && !state.hidden) || (flags & PackageManager.GET_UNINSTALLED_PACKAGES) != 0;
}

From source file:com.android.packageinstaller.PackageInstallerActivity.java

private void processPackageUri(final Uri packageUri) {
    mPackageURI = packageUri;//w  w  w.  jav a  2 s. c om

    final String scheme = packageUri.getScheme();
    final PackageUtil.AppSnippet as;

    switch (scheme) {
    case SCHEME_PACKAGE: {
        try {
            mPkgInfo = mPm.getPackageInfo(packageUri.getSchemeSpecificPart(),
                    PackageManager.GET_PERMISSIONS | PackageManager.GET_UNINSTALLED_PACKAGES);
        } catch (NameNotFoundException e) {
        }
        if (mPkgInfo == null) {
            Log.w(TAG, "Requested package " + packageUri.getScheme()
                    + " not available. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        as = new PackageUtil.AppSnippet(mPm.getApplicationLabel(mPkgInfo.applicationInfo),
                mPm.getApplicationIcon(mPkgInfo.applicationInfo));
    }
        break;

    case SCHEME_FILE: {
        File sourceFile = new File(packageUri.getPath());
        PackageParser.Package parsed = PackageUtil.getPackageInfo(sourceFile);

        // Check for parse errors
        if (parsed == null) {
            Log.w(TAG, "Parse error when parsing manifest. Discontinuing installation");
            showDialogInner(DLG_PACKAGE_ERROR);
            setPmResult(PackageManager.INSTALL_FAILED_INVALID_APK);
            return;
        }
        mPkgInfo = PackageParser.generatePackageInfo(parsed, null, PackageManager.GET_PERMISSIONS, 0, 0, null,
                new PackageUserState());
        as = PackageUtil.getAppSnippet(this, mPkgInfo.applicationInfo, sourceFile);
    }
        break;

    case SCHEME_CONTENT: {
        mStagingAsynTask = new StagingAsyncTask();
        mStagingAsynTask.execute(packageUri);
        return;
    }

    default: {
        Log.w(TAG, "Unsupported scheme " + scheme);
        setPmResult(PackageManager.INSTALL_FAILED_INVALID_URI);
        clearCachedApkIfNeededAndFinish();
        return;
    }
    }

    PackageUtil.initSnippetForNewApp(this, as, R.id.app_snippet);

    initiateInstall();
}

From source file:com.atwal.wakeup.battery.util.Utilities.java

/**
 * ??//from   ww w. java2  s. c  om
 */
public static boolean isApkInstalled(Context context, String packageName) {
    if (TextUtils.isEmpty(packageName))
        return false;
    try {
        @SuppressWarnings("unused")
        ApplicationInfo info = context.getPackageManager().getApplicationInfo(packageName,
                PackageManager.GET_UNINSTALLED_PACKAGES);
        return true;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

/**
 * Shows an alert dialog which displays a list of disabled system apps. Clicking an app in the
 * dialog enables the app./*from www. j a  va2s.  c o m*/
 */
private void showEnableSystemAppsPrompt() {
    // Disabled system apps list = {All system apps} - {Enabled system apps}
    final List<String> disabledSystemApps = new ArrayList<String>();
    // This list contains both enabled and disabled apps.
    List<ApplicationInfo> allApps = mPackageManager
            .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
    Collections.sort(allApps, new ApplicationInfo.DisplayNameComparator(mPackageManager));
    // This list contains all enabled apps.
    List<ApplicationInfo> enabledApps = mPackageManager.getInstalledApplications(0 /* Default flags */);
    Set<String> enabledAppsPkgNames = new HashSet<String>();
    for (ApplicationInfo applicationInfo : enabledApps) {
        enabledAppsPkgNames.add(applicationInfo.packageName);
    }
    for (ApplicationInfo applicationInfo : allApps) {
        // Interested in disabled system apps only.
        if (!enabledAppsPkgNames.contains(applicationInfo.packageName)
                && (applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0) {
            disabledSystemApps.add(applicationInfo.packageName);
        }
    }

    if (disabledSystemApps.isEmpty()) {
        showToast(R.string.no_disabled_system_apps);
    } else {
        AppInfoArrayAdapter appInfoArrayAdapter = new AppInfoArrayAdapter(getActivity(), R.id.pkg_name,
                disabledSystemApps, true);
        new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.enable_system_apps_title))
                .setAdapter(appInfoArrayAdapter, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int position) {
                        String packageName = disabledSystemApps.get(position);
                        mDevicePolicyManager.enableSystemApp(mAdminComponentName, packageName);
                        showToast(R.string.enable_system_apps_by_package_name_success_msg, packageName);
                    }
                }).show();
    }
}

From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java

private List<ApplicationInfo> getAllInstalledApplicationsSorted() {
    List<ApplicationInfo> allApps = mPackageManager
            .getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
    Collections.sort(allApps, new ApplicationInfo.DisplayNameComparator(mPackageManager));
    return allApps;
}