public long GetApkVersion() { return(androidPackageKitService.GetApkVersion( @"C:\Program Files (x86)\Android\android-sdk\build-tools\29.0.2" , @"C:\Users\Grzegorz\Pictures\apk\CarRepairShopSupportSystem.apk")); //Read the manifest of an Android apk file using C# .Net byte[] bytes = new byte[50 * 1024]; using (ZipArchive zip = new ZipArchive(File.OpenRead(@"C:\Users\Grzegorz\Pictures\apk\CarRepairShopSupportSystem.apk"))) using (Stream stream = zip.GetEntry("AndroidManifest.xml").Open()) { stream.Read(bytes, 0, bytes.Length); } AndroidDecompress decompress = new AndroidDecompress(bytes); string content = decompress.DecompressXML(); long versionCodeFromZip = long.Parse(Regex.Match(content, "versionCode=\"(?<versionCode>[0-9]+)\"").Groups["versionCode"].Value); return(versionCodeFromZip); decompress = new AndroidDecompress(bytes); versionCodeFromZip = decompress.GetVersionCode(); return(versionCodeFromZip); }
private void DownloadApkAndRedirectToInstallation() { ApplicationSession.userName = "******"; ApplicationSession.userPassword = "******"; long versionCode = PackageManager.GetPackageInfo(PackageName, 0).LongVersionCode; if (versionCode < androidPackageKitService.GetApkVersion()) { RunOnUiThread(delegate { Toast.MakeText(ApplicationContext, "Znaleziono nową aktualizacjie, rozpoczęto pobieranie, proszę czekać...", ToastLength.Long).Show(); }); DownloadHandler downloadHandler = new DownloadHandler(this); downloadHandler.DownloadApkAndRedirectToInstallation(); } else { StartActivity(new Intent(Application.Context, typeof(MainActivity))); } }