예제 #1
0
        /// <summary>
        /// 安装应用
        /// </summary>
        /// <param name="apkFileInfo"></param>
        /// <param name="device"></param>
        public static void InstallTo(this FileInfo apkFileInfo, IDevice device)
        {
            if (apkFileInfo == null)
            {
                throw new ArgumentNullException(nameof(apkFileInfo));
            }

            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (apkFileInfo.Extension != ".apk")
            {
                throw new ArgumentException("Is not apk file!", nameof(apkFileInfo));
            }
            using (var command = new AdbCommand(device, $"install \"{apkFileInfo.FullName}\""))
            {
                var result = command.Execute();
                if (result.ExitCode != 0)
                {
                    throw new AdbCommandFailedException(result.Output)
                          {
                              ExitCode = result.ExitCode
                          };
                }
            }
        }
예제 #2
0
        /// <summary>
        /// 推送文件到设备
        /// </summary>
        /// <param name="fileInfo"></param>
        /// <param name="device"></param>
        /// <param name="path"></param>
        public static void PushTo(this FileInfo fileInfo, IDevice device, string path)
        {
            if (fileInfo == null)
            {
                throw new ArgumentNullException(nameof(fileInfo));
            }

            if (device == null)
            {
                throw new ArgumentNullException(nameof(device));
            }

            if (path == null)
            {
                throw new ArgumentNullException(nameof(path));
            }
            using (var command = new AdbCommand(device, $"push \"{fileInfo.FullName}\" \"{path}\""))
            {
                var result = command.Execute();
                if (result.ExitCode != 0)
                {
                    throw new AdbCommandFailedException(result.Output)
                          {
                              ExitCode = result.ExitCode
                          };
                }
            }
        }
        /// <summary>
        /// 执行ADB命令
        /// </summary>
        /// <param name="device"></param>
        /// <param name="command"></param>
        /// <returns></returns>
        public static Tuple <Output, int> Adb(this IDevice device, string command)
        {
            var cmd    = new AdbCommand(device, command);
            var result = cmd.Execute();

            return(new Tuple <Output, int>(result.Output, result.ExitCode));
        }
예제 #4
0
        private void Adb(List <IDevice> devices)
        {
            var lineOutput = adbDevices.Execute().Output.LineOut;

            for (int i = 1; i < lineOutput.Count(); i++)
            {
                if (DeviceObjectFacotry.AdbTryParse(lineOutput[i], out IDevice device))
                {
                    devices.Add(device);
                }
            }
        }