Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert HttpResponse to an .apk file
    primarykey
    data
    text
    <p>The problem is this:</p> <p>I make an internet connection to some url and receive an HttpResponse with an app_example.apk.</p> <p>Then I want to create a file (an .apk) in the sdcard with this data so that this downloaded application can be installed later.</p> <p>How can I convert the HttpResponse to an .apk file?</p> <p>Let's clear some details:</p> <ul> <li>I have to get this apk file through an internet connection to my server</li> <li>I don't want to install this applications I receive on the sdcard</li> <li>All of this has to be done in my code, I cannot use android market</li> </ul> <p>I am currently writing to that file.</p> <p>What I'm doing is converting the HttpResponse to a byte[ ],</p> <p>then that byte[ ] is written to a file (an .apk) using an ObjectOutputStream.</p> <p>Like this:</p> <pre><code> // byte[] appByteArray - already has the internet response converted in bytes try { file = new File(Environment.getExternalStorageDirectory()+"/"+appName+".apk"); file.createNewFile(); FileOutputStream stream = null; stream = new FileOutputStream(file, false); ObjectOutputStream objectOut = new ObjectOutputStream(new BufferedOutputStream(stream)); objectOut.writeObject(appByteArray); objectOut.close(); } catch (Exception e) { e.printStackTrace(); } </code></pre> <p>In the end, the file is created and has the received content.</p> <p>When I try to install it, through a VIEW intent (using the default installer) I get a parse error saying that it could not find the AndroidManifest.xml.</p> <p>I think that in some step along the way, the received data is being corrupted.</p> <p>Do you have another method to solve this?</p> <p>Many thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload