Exemplo n.º 1
0
        /// <summary>
        /// 卸载Apk
        /// </summary>
        /// <param name="packageName"></param>
        /// <returns></returns>
        public static bool UninstallApk(string packageName)
        {
            string param = "uninstall " + packageName;
            string text;

            return(AdbCommand.ExecuteAdbCommand(param, out text));
        }
Exemplo n.º 2
0
        public bool Connect()
        {
            string text;

            AdbCommand.ExecuteAdbCommand("forward tcp:6666 tcp:6666", out text);
            return(this.Connect("127.0.0.1"));
        }
Exemplo n.º 3
0
        /// <summary>
        /// keyevent
        /// adb shell input keyevent KeyCode_Home
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void KeyEvrnt(string param, out string retValue)
        {
            string keyEventFile = System.Environment.CurrentDirectory + "\\KeyEvent.ini";

            string[] str_key = INI.INIOperationClass.INIGetAllItems(keyEventFile, "Key");
            string   val     = string.Empty;

            if (param.IndexOf("key") != -1)
            {
                foreach (var item in str_key)
                {
                    if (item.IndexOf("Key_Back") != -1)
                    {
                        val = item.Substring(item.IndexOf("=") + 1);
                        break;
                    }
                    else if (item.IndexOf("Key_Home") != -1)
                    {
                        val = item.Substring(item.IndexOf("=") + 1);
                        break;
                    }
                    else if (item.IndexOf("Key_Menu") != -1)
                    {
                        val = item.Substring(item.IndexOf("=") + 1);
                        break;
                    }
                }
            }
            AdbCommand.ExecuteAdbCommand("shell input keyevent " + val, out retValue);
            retValue = "Res=Pass";
        }
Exemplo n.º 4
0
        public static void ExecuteAdbShellCmd(string param, out string retValue)
        {
            string text;

            AdbCommand.ExecuteAdbCommand("shell " + param, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 5
0
        public static void Pull(string param, out string retValue)
        {
            string str = param.Substring("pull".Length);
            string text;

            AdbCommand.ExecuteAdbCommand("pull" + str, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 6
0
        public static void Remove(string param, out string retValue)
        {
            string str = param.Substring("rm".Length + 1);
            string text;

            AdbCommand.ExecuteAdbCommand("shell rm " + str, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 7
0
        /// <summary>
        /// 截屏
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void ScreenCapture(string param, out string retValue)
        {
            string str = param.Substring("snap".Length + 1);
            string text;

            AdbCommand.ExecuteAdbCommand("shell screencap " + str, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 8
0
        /// <summary>
        /// 点击
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void TouchScreen(string param, out string retValue)
        {
            string str = param.Substring("touch".Length + 1);
            string text;

            AdbCommand.ExecuteAdbCommand("shell input tap " + str, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 9
0
        /// <summary>
        /// 划屏幕指令
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void Swipe(string param, out string retValue)
        {
            string str = param.Substring("swipe".Length + 1);
            string text;

            AdbCommand.ExecuteAdbCommand("shell input swipe " + str, out text);
            retValue = "Res=Pass";
        }
Exemplo n.º 10
0
        /// <summary>
        /// apk 安装
        /// </summary>
        /// <param name="apkPath"></param>
        /// <returns></returns>
        public static bool InstallApk(string apkPath)
        {
            string param = "install -r " + apkPath;
            string text;
            bool   flag = AdbCommand.ExecuteAdbCommand(param, 20000, out text);

            Log.Debug("install " + apkPath + " return " + text);
            return(flag && text.Contains("Success"));
        }
Exemplo n.º 11
0
        /// <summary>
        /// Gps设置界面
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void CtrlGps(string param, out string retValue)
        {
            string text;

            AdbCommand.ExecuteAdbCommand("shell am start -a android.settings.LOCATION_SOURCE_SETTINGS", out text);
            string str    = param.Substring("ctrlGPS".Length + 1);
            string param2 = "shell input tap " + str;

            AdbCommand.ExecuteAdbCommand(param2);
            retValue = "Res=Pass";
        }
Exemplo n.º 12
0
        /// <summary>
        /// 打开Wifi设置界面
        /// </summary>
        /// <param name="param"></param>
        /// <param name="retValue"></param>
        public static void OpenWifiSettings(string param, out string retValue)
        {
            string text;

            AdbCommand.ExecuteAdbCommand("shell am start -a android.settings.WIFI_SETTINGS", out text);
            string str    = param.Substring("openwifiset".Length + 1);
            string param2 = "shell input tap " + str;

            AdbCommand.ExecuteAdbCommand(param2);
            retValue = "Res=Pass";
        }
Exemplo n.º 13
0
        /// <summary>
        /// SIM卡(adbcmd getval SIM1_prop_0=gsm.sim.state)
        /// </summary>
        /// <param name="name"></param>
        /// <param name="start"></param>
        /// <param name="length"></param>
        /// <param name="retValue"></param>
        public static void GetProp(string name, int start, int length, out string retValue)
        {
            string text;

            AdbCommand.ExecuteAdbCommand("shell getprop " + name, out text);
            if (start >= text.Length)
            {
                retValue = "Res=ArgumentException";
                return;
            }
            length   = Math.Min(length, text.Length - start);
            retValue = "Res=" + text.Substring(start, length);
        }
Exemplo n.º 14
0
        /// <summary>
        ///安装并启动
        /// </summary>
        /// <returns></returns>
        public static bool InstallApkAndStart()
        {
            //string text = "GeneralDev.apk";
            //if (!AdbCommand.InstallApk(text))
            //{
            //    return false;
            //}
            string text2;

            AdbCommand.ExecuteAdbCommand("shell am start -n com.qwebob.generaldev/.GeneralDevActivity", out text2);
            if (text2.Contains("error") || text2.Contains("Error"))
            {
                return(false);
            }
            return(true);
        }
Exemplo n.º 15
0
        /// <summary>
        /// 包名和类名获取
        /// </summary>
        /// <param name="retValue"></param>
        public static void GetFocusedActivity(out string retValue)
        {
            string text;

            AdbCommand.ExecuteAdbCommand("shell dumpsys activity | grep mResumedActivity", out text);
            int num = text.IndexOf("/.");

            if (num != -1)
            {
                string text2 = text.Substring(0, num);
                string text3 = text.Substring(num);
                int    num2  = text2.LastIndexOf(' ') + 1;
                int    num3  = text3.IndexOf(' ') + num;
                retValue = "Res=" + text.Substring(num2, num3 - num2);
                return;
            }
            retValue = "Res=ActivityNotFound";
        }