? ? ? 獲取很多人都會(huì)問(wèn)我為什么要寫這個(gè)博客,原因很簡(jiǎn)單,這次研發(fā)apk版本信息的時(shí)候網(wǎng)上查了很多的資料都沒(méi)有這方面的信息,因此這次功能完了想寫下方法,如果以后博友們遇到了可以直接copy,不用花很多的時(shí)間,至少有了方向。
? ? ?下面我就來(lái)說(shuō)下獲取apk版本信息所需要調(diào)用的dll吧,該程序集的版本信息為:0.85.4.369,注意哦這個(gè)版本信息很重要的,因?yàn)榭赡苣阆碌暮芏喟姹径际菬o(wú)法用的。
? ? ?下面我就來(lái)說(shuō)下研發(fā)代碼吧:代碼可能有不周全的地方:由于時(shí)間緊急沒(méi)有做優(yōu)化了:
using (ICSharpCode.SharpZipLib.Zip.ZipInputStream zip = new ICSharpCode.SharpZipLib.Zip.ZipInputStream(File.Open(apkPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)))//這里的后面連哥哥參數(shù)很重要哦,不然很有可能出現(xiàn)獨(dú)占
{
? ? ? ?using (var filestream = new FileStream(apkPath, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite))//這里的后面連哥哥參數(shù)很重要哦,不然很有可能出現(xiàn)獨(dú)占
? ? ? ? ? ? ? ? ? ? {
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);
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?}
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? }
}
? ? ? ? ? ? ? ? ? ? }
? ? ? ? }
? ? ? ?獲取出來(lái)的信息content這里我就不作解析處理了哈,需要的朋友自己處理下咯哈。
? ? ??
?