Forum Discussion

larolsen's avatar
larolsen
Contributor
8 years ago

Get version of installed Android application

Hi

 

I would like to log the version of the current Android application under test. I can't seem to figure out how to do it. Is it possible? I know you can get lots of application information when testing iOS, but I can't find anything similar for Android.

 

Best regards

Lars Lund Olsen

  • Hi Lars,

     

    To get version of the application installed on the Android device using TestComplete:

    -- Get list of the installed applications with the code like this (DelphiScript):

      DeviceObj := Mobile.Device();
      PackManagerObj := DeviceObj.PackageManager;
      Num := PackManagerObj.InstalledPackageCount;
    
      for i := 0 to Num - 1 do
      begin
        Log.AppendFolder(i);
        PackObj := PackManagerObj.InstalledPackage(i);
        // Obtain the package name
        Log.Message('The package name is: ' + PackObj.Name);
        // Obtain the path to the package on the local computer
        Log.Message('The package local path is: ' + PackObj.PCPath);
        // Obtain the path to the package on the device
        Log.Message('The package device path is: ' + PackObj.DevicePath);
    
        if (PackManagerObj.IsActivePackage(PackObj)) then
          Log.Message('The specified package is active.')
        else
          Log.Message('The specified package is not active.');
    
        Log.PopLogFolder();
      end;
    

    and get the package name from there;

     

    -- Execute code line like this:

    str := Mobile.Device.ShellExecute('dumpsys package <package_name> | grep versionName');

    the above line of code should return the string like

    versionName=2.0.2.11

     

    -- Get version number from the above string.

     

     

  • AlexKaras's avatar
    AlexKaras
    Champion Level 3

    Hi Lars,

     

    To get version of the application installed on the Android device using TestComplete:

    -- Get list of the installed applications with the code like this (DelphiScript):

      DeviceObj := Mobile.Device();
      PackManagerObj := DeviceObj.PackageManager;
      Num := PackManagerObj.InstalledPackageCount;
    
      for i := 0 to Num - 1 do
      begin
        Log.AppendFolder(i);
        PackObj := PackManagerObj.InstalledPackage(i);
        // Obtain the package name
        Log.Message('The package name is: ' + PackObj.Name);
        // Obtain the path to the package on the local computer
        Log.Message('The package local path is: ' + PackObj.PCPath);
        // Obtain the path to the package on the device
        Log.Message('The package device path is: ' + PackObj.DevicePath);
    
        if (PackManagerObj.IsActivePackage(PackObj)) then
          Log.Message('The specified package is active.')
        else
          Log.Message('The specified package is not active.');
    
        Log.PopLogFolder();
      end;
    

    and get the package name from there;

     

    -- Execute code line like this:

    str := Mobile.Device.ShellExecute('dumpsys package <package_name> | grep versionName');

    the above line of code should return the string like

    versionName=2.0.2.11

     

    -- Get version number from the above string.

     

     

    • larolsen's avatar
      larolsen
      Contributor

      Thank you very much! It was exactly what I was after. And thanks for pointing me to the Dumpsys command, that will be useful in other contexts as well :-)

       

      Best regards

      Lars Lund Olsen

      • AlexKaras's avatar
        AlexKaras
        Champion Level 3

        Great, thank you for the prompt update, Lars :)