C#獲取apk版本信息


      獲取很多人都會問我為什么要寫這個博客,原因很簡單,這次研發apk版本信息的時候網上查了很多的資料都沒有這方面的信息,因此這次功能完了想寫下方法,如果以后博友們遇到了可以直接copy,不用花很多的時間,至少有了方向。

     下面我就來說下獲取apk版本信息所需要調用的dll吧,該程序集的版本信息為:0.85.4.369,注意哦這個版本信息很重要的,因為可能你下的很多版本都是無法用的。

     下面我就來說下研發代碼吧:代碼可能有不周全的地方:由於時間緊急沒有做優化了:

  using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.Open(apkPath, FileMode.Open, FileAccess.ReadWrite,   FileShare.ReadWrite)))//這里的后面連哥哥參數很重要哦,不然很有可能出現獨占
  {

          using (var filestream = new FileStream(apkPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))//這里的后面連哥哥參數很重要哦,不然很有可能出現獨占

                    {

         using (ICSharpCode.SharpZipLib.Zip.ZipFile zipfile = new ICSharpCode.SharpZipLib.Zip.ZipFile(filestream))
                               {

                                         ICSharpCode.SharpZipLib.Zip.ZipEntry item;
                                         string content = string.Empty;
                                         while ((item = zip.GetNextEntry()) != null)
                                          {
                                                  if (item.Name == "AndroidManifest.xml")
                                                    {
                                                               byte[] bytes = new byte[50 * 1024];

                                                               using (Stream strm = zipfile.GetInputStream(item))
                                                                {
                                                                              int size = strm.Read(bytes, 0, bytes.Length);

                                                                              using (BinaryReader s = new BinaryReader(strm))
                                                                              {
                                                                                        byte[] bytes2 = new byte[size];
                                                                                         Array.Copy(bytes, bytes2, size);
                                                                                        AndroidDecompress decompress = new AndroidDecompress();
                                                                                        content = decompress.decompressXML(bytes);
                                                                             }

                                                                }
                                                  }

         }

                    }

        }

       獲取出來的信息content這里我就不作解析處理了哈,需要的朋友自己處理下咯哈。

      

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM