Skip to content Skip to sidebar Skip to footer

How To Get An .png To An Android Phone (external_sd)

I have a problem trying to get a .png image to my android phone. I am now this far: URL url = new URL ('http://oranjelan.nl/oranjelan-bg.png'); InputStream input = url.openStream

Solution 1:

In addition to what Tanis.7x pointed out, you will need to move the network operations out of the UI thread and into something such as an AyncTask. Otherwise you will not be able to interact with the application until it finishes downloading - that may result in an application unresponsive message and a force close. In more recent android versions, doing networking on the main thread is an automatic exception, even if it does not result in delay.

Solution 2:

Check out the documentation for Environment.getExternalStorageDirectory().

It returns a File (java.io.File), not a String.

I use something along the lines of:

FilestoragePath= Environment.getExternalStorageDirectory();
FileoutFile=newFile(storagePath, filename + FILE_EXTENSION);
OutputStreamoutStream=newFileOutputStream(outFile);

Solution 3:

Try something like this..

FilestoragePath=newFile(Environment.getExternalStorageDirectory()+ "/oranjelangb.png");
 OutputStreamoutput=newFileOutputStream (storagePath.getAbsoluteFile());

Post a Comment for "How To Get An .png To An Android Phone (external_sd)"