0

I'm trying to receive and install the new version of apk file using TCP Client. Apk file is received and saved to external storage successfully. But, as I try to install it, it gives me the error 'There was a problem parsing the package'. Normally, if I send apk file through bluetooth, it successfully saves and installs the package without any problem. Am I making a mistake while using FileStream? Or do I have to do some more things after saving the apk file? Code for saving file is as follows;

using (FileStream fStream = new FileStream(this.FILENAME, FileMode.Create))
                    {
                        fStream.Write(this.FILEBUFFER, 0, this.FILEBUFFER.Length);
                        fStream.Flush();
                        fStream.Close();
                    }

Your experiences are highly appreciated...

  • Check byte count of data and make sure it is the same as original. You are probably loosing data over TCP. – jdweng May 26 '22 at 15:37
  • I checked it. It has same size with the original file. On device, I renamed update.apk file as update.zip and extracted all the files in package with no problem. If there were data loss, then the files should not be extracted. Am I wrong? – Fatih Büyükegen May 26 '22 at 15:58
  • You are correct. The only reason code above would fail is if you are calling code above before all the data is received. – jdweng May 26 '22 at 16:11
  • I'm using the same method for transferring different types of files like pdf, doc, mp3 etc. but I'm not facing any problem opening these files on device. What I'm wondering is do I have to do an extra job specific for .apk files like verfication? – Fatih Büyükegen May 26 '22 at 16:23
  • Are you using FTP? FTP has text and binary mode. In binary there is no translations. In test mode some character will be changed like a linux return for a window return. – jdweng May 26 '22 at 16:42
  • Well, the file is stored in MySQL server as longblob. Android devices and the server is communicating with TCP Client using JSON data based on the request - response mechanism. I'm trying to implement an auto update method in which devices request for new version from server and server sends new apk file as byte array to clients using TCP Client. So I'm not using FTP. – Fatih Büyükegen May 26 '22 at 16:49
  • The file may of been corrupted when storing in database. You need to determine if the issue is occurring on store or read database. Start by comparing byte size of original and final and see which length is stored in the database. – jdweng May 26 '22 at 16:55
  • I checked, nothing seems to be wrong. O saved file from database to my Windows PC desktop, sent file to device with bluetooth. Again it updates package with no problem. I`m about to loose my mind... – Fatih Büyükegen May 26 '22 at 17:52
  • Use beyond compare to find differences between working and non working. You can download "Beyond Compare" for free. – jdweng May 27 '22 at 09:11

1 Answers1

0

If there is no problem with the apk you have downloaded, the cause may be the path of the apk file.

saved to external storage

What's the path of the apk file of yours? If it is in the share folder such as the Download folder, There was a problem parsing the package will appear.

The solution is in my old answer in the following case, you can check it:

Xamarin, problem with running APK - There was a problem parsing the package

Liyun Zhang - MSFT
  • 8,271
  • 1
  • 2
  • 14
  • I tried two different paths for file. First path is; System.IO.Path.Combine(Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDownloads).ToString(), filename); and the second path is System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.LocalApplicationData), filename);. Both of them resulted with the same error. – Fatih Büyükegen May 27 '22 at 06:55
  • Had you tried to get the permission I mentioned?@FatihBüyükegen – Liyun Zhang - MSFT May 27 '22 at 07:10