0

I want to check any app version in phone ( android studio ) and if the last version equal the version install in users phones app How to get any app version installed on the phone by Android Studio?

Onic Team
  • 1,620
  • 5
  • 26
  • 37
  • `BuildConfig.VERSION_CODE` provides the version code defined in your build.gradle file. – M. Palsich Jul 08 '17 at 01:32
  • no , i'm talking >>> i miss the code to check any app in phone for example if you install facebook version 2 and now the current version 3 >>>>> app checked version facebook and tell you " your facebook app is not the last version " – Yakoub Tarkaoui Jul 08 '17 at 01:42

2 Answers2

0

Get all install app info:

 List<PackageInfo> packList = getPackageManager().getInstalledPackages(0);
            for (int i=0; i < packList.size(); i++)
            {
                PackageInfo packInfo = packList.get(i);
                if (  (packInfo.applicationInfo.flags & ApplicationInfo.FLAG_SYSTEM) == 0)
                {
                    String appName = packInfo.applicationInfo.loadLabel(getPackageManager()).toString();
                    ;
                    Log.e("App " + Integer.toString(i), appName +"  ver: "+packInfo.versionCode);
                }
            }

More info:Info

Ahmad Aghazadeh
  • 16,571
  • 12
  • 101
  • 98
0

You need to iterate all application installed the app, then get each of the package name to get the package info.. in packageInfo have infomation about those app

final PackageManager packageManager = getPackageManager();
List<ApplicationInfo> installedApplications = packageManager.getInstalledApplications(PackageManager.GET_META_DATA);

List<String> vers = new ArrayList<>();

for (ApplicationInfo appInfo : installedApplications)
{
    PackageInfo packageInfo = getPackageManager().getPackageInfo(appInfo.packageName, 0);
    vers.add(packageInfo.versionName);
} 

Log.i(TAG,vers.toString());
ZeroOne
  • 8,996
  • 4
  • 27
  • 45