On Mon, Jan 4, 2010 at 6:33 PM, tsimmi <[email protected]> wrote:
> Hi!
>
> The problem is this:
>
> I make an internet connection to some url
> and receive an HttpResponse with an app_example.apk.
>
> Then I want to create a file (an .apk) in the sdcard with this data
> so that this downloaded application can be installed later.
>
> How can I convert the HttpResponse to an .apk file?

You should be able to do a byte stream copy of the data returned
straight to the SD card, something like:

FileOutputStream fos = new FileOutputStream(new
File("/sdcard/app_example.apk"));
InputStream in = myHttpResponse.getEntity().getContent();
byte[] buffer = new byte[1024];
int bufferSize = 0;
while ( (bufferSize = in.read(buffer)) > 0 ) {
    fos.write(buffer, 0, bufferSize);
}
fos.close();

Obviously you should add some checking code in there; ensure that data
is returned, the content-type is correct, the file is written to
successfully, etc.

Also make sure you have the correct permissions in your
AndroidManifest for writing to the SD card.

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to