我编写了一个工具,尝试在 C# 中使用 SharpAdbClient 在多个设备上安装多个 APK。但现在我有一个问题。如果我想安装 APK,我会遇到异常。如果我只将一台设备连接到计算机,它可以正常工作。提前致谢:
private DeviceData _deviceData;
private Configuration _configuration;
private string _folderPath;
public SetUp(DeviceData deviceData, Configuration configuration)
{
this._deviceData = deviceData;
this._configuration = configuration;
this._folderPath = @"..\..\File\App\";
StartSetUp();
}
private void StartSetUp()
{
foreach (ConfigurationAPK configurationAPK in this._configuration.ConfigurationAPKs)
{
if (configurationAPK.ConfigurationMode.ID == 1)
{
this.Install(configurationAPK.APK);
}
else if (configurationAPK.ConfigurationMode.ID == 2)
{
this.Uninstall(configurationAPK.APK);
}
}
}
public void Install(APK apk)
{
try
{
PackageManager packageManager = new PackageManager(this._deviceData, true);
packageManager.InstallPackage(this._folderPath + apk.PackageFileName, true);
}
catch (System.Exception)
{
}
}
public void Uninstall(APK apk)
{
try
{
PackageManager packageManager = new PackageManager(this._deviceData);
packageManager.UninstallPackage(apk.PackagePath);
}
catch (System.Exception)
{
}
}