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

The following are Jave code examples for showing how to use getInstalledPackages() of the android.content.pm.PackageManager class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: boohee_v5.6   File: DeviceHelper.java   View Source Code Vote up 6 votes
public ArrayList<HashMap<String, String>> getInstalledApp(boolean z) {
    try {
        PackageManager packageManager = this.context.getPackageManager();
        List<PackageInfo> installedPackages = packageManager.getInstalledPackages(0);
        ArrayList<HashMap<String, String>> arrayList = new ArrayList();
        for (PackageInfo packageInfo : installedPackages) {
            if (z || !isSystemApp(packageInfo)) {
                HashMap hashMap = new HashMap();
                hashMap.put("pkg", packageInfo.packageName);
                hashMap.put("name", packageInfo.applicationInfo.loadLabel(packageManager)
                        .toString());
                hashMap.put("version", packageInfo.versionName);
                arrayList.add(hashMap);
            }
        }
        return arrayList;
    } catch (Throwable th) {
        Ln.w(th);
        return new ArrayList();
    }
}
 
Example 2
Project: GitHub   File: ApkUtils.java   View Source Code Vote up 6 votes
/** 检查手机上是否安装了指定的软件 */
public static boolean isAvailable(Context context, String packageName) {
    // 获取packagemanager
    final PackageManager packageManager = context.getPackageManager();
    // 获取所有已安装程序的包信息
    List<PackageInfo> packageInfos = packageManager.getInstalledPackages(0);
    // 用于存储所有已安装程序的包名
    List<String> packageNames = new ArrayList<>();
    // 从pinfo中将包名字逐一取出,压入pName list中
    if (packageInfos != null) {
        for (int i = 0; i < packageInfos.size(); i++) {
            String packName = packageInfos.get(i).packageName;
            packageNames.add(packName);
        }
    }
    // 判断packageNames中是否有目标程序的包名,有TRUE,没有FALSE
    return packageNames.contains(packageName);
}
 
Example 3
Project: decoy   File: MapHelper.java   View Source Code Vote up 6 votes
private static List<PackageInfo> getComponentInfo(Context context,
		List<String> maps) {
	PackageManager pm = context.getPackageManager();
	List<PackageInfo> infos = pm.getInstalledPackages(0);
	List<PackageInfo> available = new ArrayList<PackageInfo>();
	if ((infos != null) && (infos.size() > 0))
		for (PackageInfo info : infos) {
			String packName = info.packageName;
			if (!TextUtils.isEmpty(packName) && maps.contains(packName)) {
				if (packName.equals(Autonavi_Map)) {
					if (info.versionCode >= 161)
						available.add(info);
				} else {
					available.add(info);
				}
			}
		}
	return available;
}
 
Example 4
Project: exciting-app   File: ShareQQ.java   View Source Code Vote up 6 votes
@Override
public boolean isInstalled(Context context) {
    if(context == null)
        return false;

    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;

            } else if(pn.equals("com.tencent.qzone")) {
                return true;

            }
        }
    }
    return false;
}
 
Example 5
Project: EasyReader   File: FeedbackActivity.java   View Source Code Vote up 6 votes
/**
 * 判断 用户是否安装QQ客户端
 */
public static boolean hasQQClientAvailable(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;
            LogUtils.e("pn = " + pn);
            if (pn.equalsIgnoreCase("com.tencent.qqlite") || pn.equalsIgnoreCase("com.tencent.mobileqq")) {
                return true;
            }
        }
    }
    return false;
}
 
Example 6
Project: MKAPP   File: Rule.java   View Source Code Vote up 5 votes
private static List<PackageInfo> getPackages(Context context) {
    if (cachePackageInfo == null) {
        PackageManager pm = context.getPackageManager();
        cachePackageInfo = pm.getInstalledPackages(0);
    }
    return new ArrayList<>(cachePackageInfo);
}
 
Example 7
Project: Utils   File: AppUtil.java   View Source Code Vote up 5 votes
/**
 * 获取所有已安装App信息
 * <p>{@link #getBean(PackageManager, PackageInfo)}(名称,图标,包名,包路径,版本号,版本Code,是否安装在SD卡,是否是用户程序)</p>
 * <p>依赖上面的getBean方法</p>
 *
 * @param context 上下文
 * @return 所有已安装的AppInfo列表
 */
public static List<AppInfo> getAllAppsInfo(Context context) {
    List<AppInfo> list = new ArrayList<>();
    PackageManager pm = context.getPackageManager();
    // 获取系统中安装的所有软件信息
    List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
    for (PackageInfo pi : installedPackages) {
        if (pi != null) {
            list.add(getBean(pm, pi));
        }
    }
    return list;
}
 
Example 8
Project: prevent   File: Applications.java   View Source Code Vote up 5 votes
@Override
protected Set<String> getPackageNames(PreventActivity activity) {
    Set<String> names = new HashSet<String>();
    PackageManager pm = activity.getPackageManager();
    for (PackageInfo pkgInfo : pm.getInstalledPackages(0)) {
        ApplicationInfo appInfo = pkgInfo.applicationInfo;
        if (PackageUtils.canPrevent(pm, appInfo)) {
            names.add(appInfo.packageName);
        }
    }
    return names;
}
 
Example 9
Project: PicShow-zhaipin   File: InstallAPK.java   View Source Code Vote up 5 votes
public static boolean isAppInstalled(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    List<String> pName = new ArrayList<String>();
    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            pName.add(pn);
        }
    }
    return pName.contains(packageName);
}
 
Example 10
Project: HeadlineNews   File: AppUtils.java   View Source Code Vote up 5 votes
/**
 * 获取所有已安装App信息
 * <p>{@link #getBean(PackageManager, PackageInfo)}(名称,图标,包名,包路径,版本号,版本Code,是否系统应用)</p>
 * <p>依赖上面的getBean方法</p>
 *
 * @return 所有已安装的AppInfo列表
 */
public static List<AppInfo> getAppsInfo() {
    List<AppInfo> list = new ArrayList<>();
    PackageManager pm = Utils.getContext().getPackageManager();
    // 获取系统中安装的所有软件信息
    List<PackageInfo> installedPackages = pm.getInstalledPackages(0);
    for (PackageInfo pi : installedPackages) {
        AppInfo ai = getBean(pm, pi);
        if (ai == null) continue;
        list.add(ai);
    }
    return list;
}
 
Example 11
Project: sdk3rd   File: SendShare.java   View Source Code Vote up 5 votes
boolean isApplicationInstalled(Context context, String packageName) {
    PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> list = packageManager.getInstalledPackages(0);
    for (int i = 0; i < list.size(); i++) {
        if (list.get(i).packageName.equalsIgnoreCase(packageName)) {
            return true;
        }
    }
    return false;
}
 
Example 12
Project: chromium-for-android-56-debug-video   File: InstallerDelegate.java   View Source Code Vote up 5 votes
/**
 * 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 13
Project: stynico   File: smali_layout_apktool_Util.java   View Source Code Vote up 5 votes
private boolean Ɨ(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 14
Project: stynico   File: apitils.java   View Source Code Vote up 5 votes
public static List<AppInfo> getAppList(Context context) {

        List<AppInfo> list = new ArrayList<AppInfo>();// 声明并实例化1个集合
        PackageManager pm = context.getPackageManager();//获取包管理者
        List<PackageInfo> pList = pm.getInstalledPackages(0);// 获取所有的应用程序集合
        // 循环遍历
        for (int i = 0; i < pList.size(); i++) {
            PackageInfo packageInfo = pList.get(i);// 获取每一个应用的信息

            if (isThirdPartyApp(packageInfo.applicationInfo)
                    // 不能包含本应用(不删除自己)
                    && !packageInfo.packageName.equals(context.getPackageName())) {

                // 从右边装到左边
                AppInfo appInfo = new AppInfo();
                appInfo.packageName = packageInfo.packageName;
                appInfo.versionName = packageInfo.versionName;
                appInfo.versionCode = packageInfo.versionCode;
                appInfo.firstInstallTime = packageInfo.firstInstallTime;
                appInfo.lastUpdateTime = packageInfo.lastUpdateTime;
                // 程序名称
                appInfo.appName = ((String) packageInfo.applicationInfo.loadLabel(pm)).trim();
                // 过渡
                appInfo.applicationInfo = packageInfo.applicationInfo;
                // 这行代码在运行时解除注释
                //appInfo.icon = packageInfo.applicationInfo.loadIcon(pm);
                // 计算应用的空间
                //publicSourceDir 是app的安装路径(文件夹)
                String dir = packageInfo.applicationInfo.publicSourceDir;
                long byteSize = new File(dir).length();
                appInfo.byteSize = byteSize;// 1024*1024 Byte字节
                appInfo.size = getSize(byteSize);// 1MB

                list.add(appInfo);// 添加到集合
            }// if

        }

        return list;
    }
 
Example 15
Project: mobiletailchanger   File: XposedCfgActivity.java   View Source Code Vote up 5 votes
String getAllApp(boolean isOnlyGetPackageName)
{
	String ret = "";
	PackageManager pm = getPackageManager();
	List<PackageInfo> ls = pm.getInstalledPackages(0);
	for (int i=0;i < ls.size();i++)
	{
		PackageInfo pi=ls.get(i);
		if (!isOnlyGetPackageName)
		{
			if ((pi.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)	
			{
				ret += "一般应用\n";
			}
			else
			{
				ret += "系统应用\n";
			}
		}
		if (!isOnlyGetPackageName)
		{
			ret += pi.applicationInfo.loadLabel(pm).toString() + "\n" + pi.packageName + "\n\n";
		}
		else
		{
			ret += pi.packageName + "\n";
		}
	}
	return ret;
}
 
Example 16
Project: Saiy-PS   File: Installed.java   View Source Code Vote up 5 votes
/**
 * Get a list of all of the installed applications that hold the {@link Manifest.permission#CONTROL_SAIY},
 * regardless of whether or not the permission has been explicitly granted. The results exclude our own
 * package.
 *
 * @param ctx the application context
 * @return an ArrayList containing a {@link Pair} with the first parameter containing the application name
 * and the second the package name.
 */
public static ArrayList<Pair<String, String>> declaresSaiyPermissionLegacy(@NonNull final Context ctx) {

    final ArrayList<Pair<String, String>> holdsPermission = new ArrayList<>();
    final PackageManager pm = ctx.getPackageManager();
    final List<PackageInfo> apps = pm.getInstalledPackages(PackageManager.GET_PERMISSIONS);

    CharSequence appNameChar;
    String appName;
    String[] permissions;
    for (final PackageInfo packageInfo : apps) {

        permissions = packageInfo.requestedPermissions;
        if (permissions != null) {

            for (final String permission : permissions) {
                if (pCONTROL_SAIY.matcher(permission).matches()) {

                    appNameChar = packageInfo.applicationInfo.loadLabel(pm);

                    if (appNameChar != null) {
                        appName = packageInfo.applicationInfo.loadLabel(pm).toString();

                        if (UtilsString.notNaked(appName)) {
                            if (!pSAIY_PACKAGE.matcher(packageInfo.packageName).matches()) {
                                holdsPermission.add(new Pair<>(appName, packageInfo.packageName));
                            }
                            break;
                        }
                    }

                    holdsPermission.add(new Pair<>(packageInfo.packageName, packageInfo.packageName));
                }
            }
        }
    }

    return holdsPermission;
}
 
Example 17
Project: PicShow-zhaipin   File: InstallAPK.java   View Source Code Vote up 5 votes
public static boolean isAppInstalled(Context context, String packageName) {
    final PackageManager packageManager = context.getPackageManager();
    List<PackageInfo> pinfo = packageManager.getInstalledPackages(0);
    List<String> pName = new ArrayList<String>();
    if (pinfo != null) {
        for (int i = 0; i < pinfo.size(); i++) {
            String pn = pinfo.get(i).packageName;
            pName.add(pn);
        }
    }
    return pName.contains(packageName);
}
 
Example 18
Project: SocialSdkLibrary   File: CommonUtils.java   View Source Code Vote up 5 votes
public static boolean isAppInstall(Context context, String pkgName) {
    PackageManager pm = context.getPackageManager();
    if (pm == null) {
        return false;
    }
    List<PackageInfo> packages = pm.getInstalledPackages(0);
    boolean result = false;
    for (PackageInfo info : packages) {
        if (TextUtils.equals(info.packageName.toLowerCase(), pkgName)) {
            result = true;
            break;
        }
    }
    return result;
}
 
Example 19
Project: WearVibrationCenter   File: AppPickerFragment.java   View Source Code Vote up 5 votes
@Override
protected List<AppInfoStorage> doInBackground(Void... params) {
    if (getActivity() == null) {
        return null;
    }

    Context context = getActivity();

    if (context == null) {
        return null;
    }

    final PackageManager pm = context.getPackageManager();
    List<PackageInfo> packages = pm.getInstalledPackages(0);

    List<AppInfoStorage> newApps = new ArrayList<>();

    for (PackageInfo packageInfo : packages) {
        try {
            ApplicationInfo appInfo = pm.getApplicationInfo(packageInfo.packageName, 0);

            boolean isSystemApp = ((appInfo.flags & ApplicationInfo.FLAG_SYSTEM) != 0);
            if (isSystemApp == systemApps) {
                AppInfoStorage storage = new AppInfoStorage(appInfo.packageName, pm.getApplicationLabel(appInfo));

                newApps.add(storage);
            }
        } catch (PackageManager.NameNotFoundException ignored) {
        }

    }

    Collections.sort(newApps);

    return newApps;
}
 
Example 20
Project: Android_AutobootKodi   File: Receiver.java   View Source Code Vote up 4 votes
@Override
public void onReceive(Context context, Intent intent) {
    boolean findApp = false;
    if (intent.getAction().equals(action_boot)) {
        Log.i(logTag, "Receive " + action_boot);
        Intent mBootIntent = new Intent(context, AutoBootKodi.class);
        mBootIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(mBootIntent);
        Log.i(logTag, "Done!");
        String intentName = new String("");
        PackageManager packageManager = context.getPackageManager();
        ArrayList<AppInfo> appList = new ArrayList<AppInfo>();
        List<PackageInfo> packages = packageManager.getInstalledPackages(0);
        for(int i = 0;i < packages.size();i++) {
            PackageInfo packageInfo = packages.get(i);
            AppInfo tempInfo = new AppInfo();
            tempInfo.appName = packageInfo.applicationInfo.loadLabel(packageManager).toString();
            tempInfo.packageName = packageInfo.packageName;
            tempInfo.versionName = packageInfo.versionName;
            tempInfo.versionCode = packageInfo.versionCode;
            tempInfo.appIcon = packageInfo.applicationInfo.loadIcon(packageManager);
            // if want to launch the app not system app, add below judgement
            if((packageInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
            {
                if (tempInfo.packageName.equals("org.xbmc.xbmc")) {
                    intentName = new String(context.getResources().getString(R.string.boot_app_name) +
                            context.getResources().getString(R.string.old_app_name));
                    findApp =true;
                } else if (tempInfo.packageName.equals("org.xbmc.kodi")) {
                    intentName = new String(context.getResources().getString(R.string.boot_app_name) +
                            context.getResources().getString(R.string.new_app_name));
                    findApp =true;
                }
                if (findApp) {
                    appList.add(tempInfo);
                    Log.i(logTag, "intentName is " + intentName);
                    tempInfo.print();
                }
            }
        }

        if (findApp) { // should use flag findApp to check the intentName has string or null
            Intent mBootUpIntent = packageManager.getLaunchIntentForPackage(intentName);
            mBootUpIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(mBootUpIntent);
        }

    }

}