GetPackageFromAPK Method

Applies to TestComplete 14.10, last modified on June 5, 2019

Description

The GetPackageFromAPK method returns information about the package that corresponds to the specified package file (*.apk) stored on the local computer. The needed path is passed to the method as a parameter.

Declaration

PackageManagerObj.GetPackageFromAPK(PCPath)

PackageManagerObj An expression, variable or parameter that specifies a reference to a PackageManager object
PCPath [in]    Required    String    
Result PackageObject

Applies To

The method is applied to the following object:

Parameters

The method has the following parameter:

PCPath

Specifies the path to the package file (.apk) stored on the local computer.

Result Value

The PackageObject object that corresponds to the specified package file (*.apk). If the package is not found, the method posts an error to the test log.

Example

The code below obtains the PackageObject object that corresponds to the specified package file (*.apk), installs this package on the device, launches the default activity for the package and then removes the package from the device:

JavaScript, JScript

function Test()
{
  // Obtain the PackageObject object
  var DeviceObj = Mobile.Device("VirtualBox");
  var PackManagerObj = DeviceObj.PackageManager;
  var PackObj = PackManagerObj.GetPackageFromAPK("C:\\Work\\MyPackage.apk");
  // Install the package
  PackManagerObj.InstallPackage(PackObj);
  // Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj);
  // Remove the package
  PackManagerObj.RemovePackage(PackObj);
}

Python

def Test():
  # Obtain the PackageObject object
  DeviceObj = Mobile.Device("VirtualBox")
  PackManagerObj = DeviceObj.PackageManager
  PackObj = PackManagerObj.GetPackageFromAPK("C:\\Work\\MyPackage.apk")
  # Install the package
  PackManagerObj.InstallPackage(PackObj)
  # Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj)
  # Remove the package
  PackManagerObj.RemovePackage(PackObj)

VBScript

Sub Test
  ' Obtain the PackageObject object
  Set DeviceObj = Mobile.Device("VirtualBox")
  Set PackManagerObj = DeviceObj.PackageManager
  Set PackObj = PackManagerObj.GetPackageFromAPK("C:\Work\MyPackage.apk")
  ' Install the package
  PackManagerObj.InstallPackage(PackObj)
  ' Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj)
  ' Remove the package
  PackManagerObj.RemovePackage(PackObj)
End Sub

DelphiScript

function Test;
var DeviceObj, PackManagerObj, PackObj: OleVariant;
begin
  // Obtain the PackageObject object
  DeviceObj := Mobile.Device('VirtualBox');
  PackManagerObj := DeviceObj.PackageManager;
  PackObj := PackManagerObj.GetPackageFromAPK('C:\Work\MyPackage.apk');
  // Install the package
  PackManagerObj.InstallPackage(PackObj);
  // Launch the default activity for the package
  PackManagerObj.LaunchPackage(PackObj);
  // Remove the package
  PackManagerObj.RemovePackage(PackObj);
end;

C++Script, C#Script

function Test()
{
  // Obtain the PackageObject object
  var DeviceObj = Mobile["Device"]("VirtualBox");
  var PackManagerObj = DeviceObj["PackageManager"];
  var PackObj = PackManagerObj["GetPackageFromAPK"]("C:\\Work\\MyPackage.apk");
  // Install the package
  PackManagerObj["InstallPackage"](PackObj);
  // Launch the default activity for the package
  PackManagerObj["LaunchPackage"](PackObj);
  // Remove the package
  PackManagerObj["RemovePackage"](PackObj);
}

See Also

PackageManager Object
Installing Packages on Devices

Highlight search results