Android Question [SOLVED] There was a problem with Download File Example

incendio

Well-Known Member
Licensed User
Longtime User
Hi guys,

I follow this tutorial to download apk file from the B4J server into smartphone.

The operation was successful but there was something strange with the downloaded file .
The icon of the apk was not displayed, see the attachment file. And when I double clicked this file, the error
There was a problem parsing the package raised.

If I copied manually the apk to smartphone, the icon from the apk was showed.

Here is the code to copied downloded file
B4X:
Sub dd_Complete(Job As HttpJob)
    Log("Job completed: " & Job.Success)
  
    Dim o As OutputStream
    o = File.OpenOutput(File.DirDefaultExternal, "Test.apk", False)
    File.Copy2(Job.GetInputStream,o)
    Job.Release
End Sub

I tried to download that file via browser in smartphone & install it, it was OK.

So the problem seem in download file or copy from Inputstream to Outputstream.

Any idea how to solved this?
 

Attachments

  • Test.jpg
    Test.jpg
    173.6 KB · Views: 129
Last edited:

Alex_197

Well-Known Member
Licensed User
Longtime User
1. In the IDE - click on Ctrl+P to clean up the project.
2. Just reboot your phone.
3. It might happens if you are running Android 8 or 9 but trying to upload the B4XPage project. If it's a case - you will get this error. The only option is to upgrade your phone to 10+
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
I have tested to download and exe & apk file with the app and download manually via browser in smartphone.

With browser, the file size (exe & apk) are exactly the same and it can run on Windows OS/Android without a problem.

With the app, the file size are smaller and can't run both on Windows/Android.

I think there was a problem with Download file example or copy from Inputstream to Outputstream.
 
Upvote 0

incendio

Well-Known Member
Licensed User
Longtime User
After looking your example, found that I was missing 1 important line which is to close OutputStream.

Never work with OutputStream before, don't know that it must be closed.

All worked now, thanks.
 
Upvote 0
Top