tags:

views:

290

answers:

2

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?

Thank you all

+2  A: 

Be aware of that you need the WRITE_EXTERNAL_STORAGE permission in your application, but you can just write to the sdcard then. Every content, every filename you wish. Installing is, however, another thing.

moritz
Thanks,but I already have that permission andI am currently writing to that file.What I'm doing is converting the HttpResponse to a byte[],then that byte[] is written to a file (an .apk) using an ObjectOutputStream....
Tsimmi
Like this:// byte[] appByteArray - already has the internet response converted in bytestry {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();}
Tsimmi
sounds fine, it works?
moritz
In the end, the file is created and has the received content.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.I think that in some step along the way, the received data is being corrupted.Do you have another method to solve this?Many thanks
Tsimmi
i guess Dinedal made a good point, despite all efforts to install an app from sdcard programmatically, most people are used to getting their apps over the app store, so you should possibly save yourself the hazzle and upload it their. Back to the question: no, i dont have a better idea.. maybe hash the contents to see if the content there matches the source file?
moritz
+1  A: 

If you are trying to install another application (like an add-on or additional data), you should publish the add-on on the market, and use intents to ask the market to take over the download and install process of the additional data.

Installing to the SD card can't be done via the API's, as far as I am aware, you can only install applications to the device's internal memory. Downloading additional data should either be done via the market as an APK, or just download a zip with your App and install the additional data to the SD card that way.

You will need the WRITE_EXTERNAL_STORAGE permission like moritz suggests if you are writing to the SD card in any way.

Dinedal
I created a more detailed question about this problem,here:http://stackoverflow.com/questions/2001636/convert-httpresponse-to-an-apk-fileplease, followThanks
Tsimmi