0

I want to save an image from the drawable directory to the download folder in the phone.

The code I was trying is:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tradoficial); File sd = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); String fileName = "test.jpg"; File dest = new File(sd, fileName); try { FileOutputStream out; out = new FileOutputStream(dest); bitmap.compress(Bitmap.CompressFormat.JPEG, 100, out); out.flush(); out.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } 

But nothing happens on my phone. Is there anything wrong?

Thanks a lot!

4
  • do you have the WRITE_EXTERNAL_STORAGE permission? Commented Jan 4, 2013 at 21:21
  • Sorry, I'm pretty new with developes for Android. How do I set that permission? Commented Jan 4, 2013 at 21:23
  • in the AndroidManifest.xml file, add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> under the <manifest> tag and see if it does any difference Commented Jan 4, 2013 at 21:25
  • It worked perfectly, I could have spent 100 years trying to figure it out haha thanks a lot! Commented Jan 4, 2013 at 21:30

1 Answer 1

2

in the AndroidManifest.xml file, add <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/> under the <manifest> tag

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.