Java Code Examples for android.content.pm.PackageManager#getInstalledPackages()

The following examples show how to use android.content.pm.PackageManager#getInstalledPackages() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XposedApp.java    From EdXposedManager with GNU General Public License v3.0 6 votes vote down vote up
public static boolean checkAppInstalled(Context context, String pkgName) {
    if (pkgName == null || pkgName.isEmpty()) {
        return false;
    }
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> info = packageManager.getInstalledPackages(0);
    if (info == null || info.isEmpty()) {
        return false;
    }
    for (int i = 0; i < info.size(); i++) {
        if (pkgName.equals(info.get(i).packageName)) {
            return true;
        }
    }
    return false;
}
 
Example 2
Source File: Utils.java    From KUtils with Apache License 2.0 6 votes vote down vote up
/**
 * 获取系统中所有的应用
 *
 * @param context 上下文
 * @return 应用信息List
 */
public static List<PackageInfo> getAllApps(Context context) {

    List<PackageInfo> apps = new ArrayList<PackageInfo>();
    PackageManager pManager = context.getPackageManager();
    List<PackageInfo> paklist = pManager.getInstalledPackages(0);
    for (int i = 0; i < paklist.size(); i++) {
        PackageInfo pak = paklist.get(i);
        if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <=
                0) {
            // customs applications
            apps.add(pak);
        }
    }
    return apps;
}
 
Example 3
Source File: PackageInstallUtils.java    From RxJava2RetrofitDemo with Apache License 2.0 5 votes vote down vote up
private static boolean isAppInstall(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    // 获取所有已安装程序的包信息
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    for (int i = 0; i < pinfo.size(); i++) {
        if (pinfo.get(i).packageName.equalsIgnoreCase(packageName))
            return true;
    }
    return false;
}
 
Example 4
Source File: Utils.java    From A-week-to-develop-android-app-plan with Apache License 2.0 5 votes vote down vote up
/**
 * 判断qq是否可用
 *
 * @param context
 * @return
 */
public static boolean isQQClientAvailable(Context context) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            if (pn.equals("com.tencent.mobileqq")) {
                return true;
            }
        }
    }
    return false;
}
 
Example 5
Source File: InstallerDelegate.java    From delion with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if the app has been installed on the system.
 * @param packageManager PackageManager to use.
 * @param packageName Name of the package to check.
 * @return True if the PackageManager reports that the app is installed, false otherwise.
 */
public static boolean isInstalled(PackageManager packageManager, String packageName) {
    List<PackageInfo> packs = packageManager.getInstalledPackages(0);
    for (int i = 0; i < packs.size(); i++) {
        if (TextUtils.equals(packs.get(i).packageName, packageName)) return true;
    }
    return false;
}
 
Example 6
Source File: Utils.java    From Mobike with Apache License 2.0 5 votes vote down vote up
/**
 * 检测是否有某个应用
 * */
public static boolean hasApp(Context ctx, String packageName) {
    PackageManager manager = ctx.getPackageManager();
    List<PackageInfo> apps = manager.getInstalledPackages(0);
    if (apps != null) {
        for (int i = 0; i < apps.size(); i++) {
            if (apps.get(i).packageName.equals(packageName)) {
                return true;
            }
        }
    }
    return false;
}
 
Example 7
Source File: AmazonBillingProvider.java    From OPFIab with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isAvailable() {
    final PackageManager packageManager = context.getPackageManager();
    for (final PackageInfo info : packageManager.getInstalledPackages(0)) {
        if (PATTERN_STORE_PACKAGE.matcher(info.packageName).matches()) {
            // Check sdk tester package if app is in sandbox mode.
            return !PurchasingService.IS_SANDBOX_MODE
                    || OPFUtils.isInstalled(context, TESTER_PACKAGE);
        }
    }
    return false;
}
 
Example 8
Source File: SettingsActivity.java    From KeyBlocker with GNU General Public License v3.0 5 votes vote down vote up
private void getAppInfo(Context ctx, ArrayList<String> PkgHave) {
    PackageManager pm = ctx.getPackageManager();
    boolean activity_filter = mSp.getBoolean(Config.KEYBLOCK_ACTIVITY_FILTER, true);
    List<PackageInfo> info = activity_filter ? pm.getInstalledPackages(PackageManager.GET_ACTIVITIES) : pm.getInstalledPackages(0);

    Iterator<PackageInfo> it = info.iterator();
    while (it.hasNext()) {
        PackageInfo packageinfo = it.next();
        ActivityInfo[] actInfo = packageinfo.activities;
        if (packageinfo.packageName.equalsIgnoreCase(ctx.getPackageName())) {
            it.remove();
            continue;
        }
        if (actInfo == null && activity_filter) {
            it.remove();
        }
    }

    BaseMethod.orderPackageList(ctx, info);
    AppNames = new String[info.size()];
    PkgNames = new String[info.size()];
    AppState = new boolean[info.size()];
    for (int i = 0; i < info.size(); i++) {
        String pkgname = info.get(i).packageName;
        AppNames[i] = info.get(i).applicationInfo.loadLabel(ctx.getPackageManager()).toString();
        PkgNames[i] = pkgname;
        AppState[i] = PkgHave.contains(pkgname);
    }
}
 
Example 9
Source File: QQShareInstance.java    From ShareLoginPayUtil with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInstall(Context context) {
    PackageManager pm = context.getPackageManager();
    if (pm == null) {
        return false;
    }

    List<PackageInfo> packageInfos = pm.getInstalledPackages(0);
    for (PackageInfo info : packageInfos) {
        if (TextUtils.equals(info.packageName.toLowerCase(), "com.tencent.mobileqq")) {
            return true;
        }
    }
    return false;
}
 
Example 10
Source File: AppUtils.java    From BigApp_Discuz_Android with Apache License 2.0 5 votes vote down vote up
public static boolean isAvilible(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();// 获取packagemanager
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);// 获取所有已安装程序的包信息
    List<String> pName = new ArrayList<String>();// 用于存储所有已安装程序的包名
    // 从pinfo中将包名字逐一取出,压入pName list中
    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            pName.add(pn);
        }
    }
    return pName.contains(packageName);// 判断pName中是否有目标程序的包名,有TRUE,没有FALSE
}
 
Example 11
Source File: IgnorePreference.java    From pebble-notifier with MIT License 5 votes vote down vote up
@Override
protected void onPreExecute(){
    PackageManager pm = getContext().getPackageManager();
    try {
        pkgAppsList = pm.getInstalledPackages(0);
    } catch (RuntimeException e){
        //this is usually thrown when people have too many things installed (or bloatware in the case of Samsung devices)
        pm = getContext().getPackageManager();
        appsList = pm.getInstalledApplications(0);
    }

}
 
Example 12
Source File: ResourceManager.java    From GreenDamFileExploere with Apache License 2.0 5 votes vote down vote up
public List<PackageInfo> getCustomApps() {
    List<PackageInfo> apps = new ArrayList<PackageInfo>();
    PackageManager pm = mContext.getPackageManager();
    // 获取手机内所有应用
    List<PackageInfo> paklist = pm.getInstalledPackages(0);
    for (int i = 0; i < paklist.size(); i++) {
        PackageInfo pak = (PackageInfo) paklist.get(i);
        if ((pak.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) <= 0) {
            apps.add(pak);
        }
    }
    return apps;
}
 
Example 13
Source File: QQShareInstance.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isInstall(Context context) {
    PackageManager pm = context.getPackageManager();
    if (pm == null) {
        return false;
    }

    List<PackageInfo> packageInfos = pm.getInstalledPackages(0);
    for (PackageInfo info : packageInfos) {
        if (TextUtils.equals(info.packageName.toLowerCase(), "com.tencent.mobileqq")) {
            return true;
        }
    }
    return false;
}
 
Example 14
Source File: SendShare.java    From sdk3rd with Apache License 2.0 5 votes vote down vote up
boolean isApplicationInstalled(Context context, String packageName) {
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> list = pm.getInstalledPackages(0);
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).packageName.equalsIgnoreCase(packageName)) {
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: InternalRootDetection.java    From cordova-plugin-iroot with MIT License 5 votes vote down vote up
/**
 * Checks for installed packages which are known to be present on rooted devices.
 *
 * @param context Used for accessing the package manager.
 */
private boolean checkInstalledPackages(final Context context) {
    final PackageManager pm = context.getPackageManager();
    final List<PackageInfo> installedPackages = pm.getInstalledPackages(0);

    int rootOnlyAppCount = 0;

    for (PackageInfo packageInfo : installedPackages) {
        final String packageName = packageInfo.packageName;

        if (Constants.BLACKLISTED_PACKAGES.contains(packageName)) {
            LOG.d(Constants.LOG_TAG, String.format("[checkInstalledPackages] Package [%s] found in BLACKLISTED_PACKAGES", packageName));

            return true;
        }

        if (Constants.ROOT_ONLY_APPLICATIONS.contains(packageName)) {
            LOG.d(Constants.LOG_TAG, String.format("[checkInstalledPackages] Package [%s] found in ROOT_ONLY_APPLICATIONS", packageName));

            rootOnlyAppCount += 1;
        }

        // Check to see if the Cydia Substrate exists.
        if (Constants.CYDIA_SUBSTRATE_PACKAGE.equals(packageName)) {
            LOG.d(Constants.LOG_TAG, String.format("[checkInstalledPackages] Package [%s] found in CYDIA_SUBSTRATE_PACKAGE", packageName));

            rootOnlyAppCount += 1;
        }
    }

    LOG.d(Constants.LOG_TAG, String.format("[checkInstalledPackages] count of root-only apps: %s", rootOnlyAppCount));

    boolean result = rootOnlyAppCount > 2; // todo: why?

    LOG.d(Constants.LOG_TAG, String.format("[checkInstalledPackages] result: %s", result));

    return result;
}
 
Example 16
Source File: RandomLookActivity.java    From zhizhihu with Apache License 2.0 5 votes vote down vote up
private boolean isValid(Context context, String packageName) {
    boolean hasInstalled = false;
    PackageManager pm = context.getPackageManager();
    List<PackageInfo> list = pm.getInstalledPackages(PackageManager.PERMISSION_GRANTED);
    for (PackageInfo p : list) {
        if (packageName != null && packageName.equals(p.packageName)) {
            hasInstalled = true;
            break;
        }
    }
    return hasInstalled;
}
 
Example 17
Source File: AptoideUtils.java    From aptoide-client-v8 with GNU General Public License v3.0 4 votes vote down vote up
public static List<PackageInfo> getAllInstalledApps(PackageManager packageManager) {
  return packageManager.getInstalledPackages(PackageManager.GET_SIGNATURES);
}
 
Example 18
Source File: ShortcutHelper.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Calls the native |callbackPointer| with lists of information on all installed WebAPKs.
 *
 * @param callbackPointer Callback to call with the information on the WebAPKs found.
 */
@CalledByNative
public static void retrieveWebApks(long callbackPointer) {
    List<String> names = new ArrayList<>();
    List<String> shortNames = new ArrayList<>();
    List<String> packageNames = new ArrayList<>();
    List<Integer> shellApkVersions = new ArrayList<>();
    List<Integer> versionCodes = new ArrayList<>();
    List<String> uris = new ArrayList<>();
    List<String> scopes = new ArrayList<>();
    List<String> manifestUrls = new ArrayList<>();
    List<String> manifestStartUrls = new ArrayList<>();
    List<Integer> displayModes = new ArrayList<>();
    List<Integer> orientations = new ArrayList<>();
    List<Long> themeColors = new ArrayList<>();
    List<Long> backgroundColors = new ArrayList<>();

    Context context = ContextUtils.getApplicationContext();
    PackageManager packageManager = context.getPackageManager();
    for (PackageInfo packageInfo : packageManager.getInstalledPackages(0)) {
        if (WebApkValidator.isValidWebApk(context, packageInfo.packageName)) {
            // Pass non-null URL parameter so that {@link WebApkInfo#create()}
            // return value is non-null
            WebApkInfo webApkInfo = WebApkInfo.create(packageInfo.packageName, "",
                    ShortcutSource.UNKNOWN, false /* forceNavigation */);
            if (webApkInfo != null) {
                names.add(webApkInfo.name());
                shortNames.add(webApkInfo.shortName());
                packageNames.add(webApkInfo.webApkPackageName());
                shellApkVersions.add(webApkInfo.shellApkVersion());
                versionCodes.add(packageInfo.versionCode);
                uris.add(webApkInfo.uri().toString());
                scopes.add(webApkInfo.scopeUri().toString());
                manifestUrls.add(webApkInfo.manifestUrl());
                manifestStartUrls.add(webApkInfo.manifestStartUrl());
                displayModes.add(webApkInfo.displayMode());
                orientations.add(webApkInfo.orientation());
                themeColors.add(webApkInfo.themeColor());
                backgroundColors.add(webApkInfo.backgroundColor());
            }
        }
    }
    nativeOnWebApksRetrieved(callbackPointer, names.toArray(new String[0]),
            shortNames.toArray(new String[0]), packageNames.toArray(new String[0]),
            integerListToIntArray(shellApkVersions), integerListToIntArray(versionCodes),
            uris.toArray(new String[0]), scopes.toArray(new String[0]),
            manifestUrls.toArray(new String[0]), manifestStartUrls.toArray(new String[0]),
            integerListToIntArray(displayModes), integerListToIntArray(orientations),
            longListToLongArray(themeColors), longListToLongArray(backgroundColors));
}
 
Example 19
Source File: LocalVpnService.java    From BaoLianDeng with GNU General Public License v3.0 4 votes vote down vote up
private ParcelFileDescriptor establishVPN() throws Exception {

        NatSessionManager.clearAllSessions();

        Builder builder = new Builder();
        builder.setMtu(ProxyConfig.Instance.getMTU());

        IPAddress ipAddress = ProxyConfig.Instance.getDefaultLocalIP();
        LOCAL_IP = CommonMethods.ipStringToInt(ipAddress.Address);

        builder.addAddress(ipAddress.Address, ipAddress.PrefixLength);
        if (ProxyConfig.IS_DEBUG)
            Log.d(Constant.TAG, String.format("addAddress: %s/%d\n", ipAddress.Address, ipAddress.PrefixLength));

        for (ProxyConfig.IPAddress dns : ProxyConfig.Instance.getDnsList()) {
            builder.addDnsServer(dns.Address);
        }

        if (m_Blacklist == null) {
            m_Blacklist = getResources().getStringArray(R.array.black_list);
        }

        ProxyConfig.Instance.resetDomain(m_Blacklist);

        for (String routeAddress : getResources().getStringArray(R.array.bypass_private_route)) {
            String[] addr = routeAddress.split("/");
            builder.addRoute(addr[0], Integer.parseInt(addr[1]));
        }

        builder.addRoute(CommonMethods.ipIntToString(ProxyConfig.FAKE_NETWORK_IP), 16);

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            PackageManager packageManager = getPackageManager();
            List<PackageInfo> list = packageManager.getInstalledPackages(0);
            HashSet<String> packageSet = new HashSet<>();

            for (int i = 0; i < list.size(); i++) {
                PackageInfo info = list.get(i);
                packageSet.add(info.packageName);
            }

            for (String name : getResources().getStringArray(R.array.bypass_package_name)) {
                if (packageSet.contains(name)) {
                    builder.addDisallowedApplication(name);
                }
            }
        }

        Intent intent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
        builder.setConfigureIntent(pendingIntent);

        builder.setSession(ProxyConfig.Instance.getSessionName());
        ParcelFileDescriptor pfdDescriptor = builder.establish();
        onStatusChanged(ProxyConfig.Instance.getSessionName() + " " + getString(R.string.vpn_connected_status), true);
        return pfdDescriptor;
    }
 
Example 20
Source File: DevicePluginManager.java    From DeviceConnect-Android with MIT License 3 votes vote down vote up
/**
 * インストールされている BroadcastReceiver 型プラグインのリストを取得します.
 * <p>
 * 従来の Device Connect は BroadcastReceiver を用いて各プラグインと通信を行なっていました。<br>
 * ここでは、下位互換のために BroadcastReceiver 型のプラグインのリスト取得を行います。
 * </p>
 * @param pkgMgr パッケージマネージャ
 * @return サービスに対応したプラグインのリスト
 */
private List<DevicePlugin> getInstalledReceivers(final PackageManager pkgMgr) {
    List<DevicePlugin> result = new ArrayList<>();
    List<PackageInfo> pkgList = pkgMgr.getInstalledPackages(PackageManager.GET_RECEIVERS | PackageManager.GET_PROVIDERS);
    for (PackageInfo pkg : pkgList) {
        result.addAll(getInstalledReceiversForPackage(pkgMgr, pkg));
    }
    return result;
}