Exemple #1
0
        public static bool GetApkInfo(string path, out ApkInfo apkInfo)
        {
            bool bret = true;
            apkInfo = null;

            StringBuilder result;
            bret = AdbCmd.ExecuteCommand(GlobalSys.aaptPath, "dump badging \""+path+"\"", out result);
            string str = result.ToString();
            string[] myarray = str.Split(new char[] { '\r', '\r', '\n' });
            if (bret)
            {
                apkInfo = new ApkInfo();
                apkInfo.filePath = path;
                apkInfo.uses_permission = new List<string>();
                for (int i = 0; i < myarray.Length; i++)
                {
                    if (myarray[i].Length > 0)
                    {
                        if (myarray[i].Contains("package:"))
                        {
                            apkInfo.package = GetQuoteString(myarray[i], "name=");
                            apkInfo.versionName = GetQuoteString(myarray[i], "versionName=");
                        }
                        else if (myarray[i].Contains("application:"))
                        {
                            apkInfo.label = GetQuoteString(myarray[i], "label=");
                            apkInfo.iconPath = GetQuoteString(myarray[i], "icon=");
                        }
                        else if (myarray[i].Contains("uses-permission:"))
                        {
                             apkInfo.uses_permission.Add(GetQuoteString(myarray[i], "uses-permission"));
                        }
                        else if (myarray[i].Contains("sdkVersion:"))
                        {
                            apkInfo.sdkVersion = GetQuoteString(myarray[i], "sdkVersion");
                            int ver = Int32.Parse(apkInfo.sdkVersion);
                            apkInfo.versionDroid = toAndroidVer[ver - 1];
                        }
                        else if (myarray[i].Contains("native-code:"))
                        {
                            apkInfo.arch = GetQuoteString(myarray[i], "native-code");
                        }
                    }
                }
            }
            else
            {
                MessageBox.Show("");
            }
            return bret;
        }
Exemple #2
0
        public static bool InstallApk(ApkInfo apkInfo, bool toSdcard)
        {
            bool bret = true;
            StringBuilder res;

            string srcPath = apkInfo.filePath;
            string srcDir = GetPcFilePath(srcPath);
            string srcName = GetPcFileName(srcPath);
            Random rand = new Random();
            string tmpName = "tmpname" + rand.Next(10001) + ".apk";
            string newPath = srcDir + tmpName;
            MovePcFile(srcPath, newPath);
            apkInfo.filePath = newPath;

            string cmdToSdcard = "install -s \"" + newPath + "\"";
            string cmdDefault = "install \"" + newPath + "\"";
            if (toSdcard)
            {
                bret = AdbCmd.ExecuteADBCommand(cmdToSdcard, out res);
                if (!bret)
                    bret = AdbCmd.ExecuteADBCommand(cmdDefault, out res);
            }
            else
            {
                bret = AdbCmd.ExecuteADBCommand(cmdDefault, out res);
            }

            MovePcFile(newPath, srcPath);
            apkInfo.filePath = srcPath;

            string strres = res.ToString();
            return bret;
        }