Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem might be with the directory you're trying to store the file in. To save files to the SD card you don't need any special permissions, but the way you get the folder reference is different to how you've done it. It also depends on whether you want to save the image in a way that can be retrieved by the MediaStore (i.e. things like the gallery or albums application, or any other app that relies on those to find images) or not. Assuming you want it to be listed in the MediaStore, here's the code to do that:</p> <pre><code>ContentValues newImage = new ContentValues(2); newImage.put(Media.DISPLAY_NAME, "whatever name you want shown"); newImage.put(Media.MIME_TYPE, "image/png"); Uri uri = contentResolver.insert(Media.EXTERNAL_CONTENT_URI, newImage); try { Bitmap bitmap = //get your bitmap from the Camera, however that's done OutputStream out = contentResolver.openOutputStream(uri); boolean success = bitmap.compress(Bitmap.CompressFormat.PNG, 100, out); out.close(); if (success){ Log.d("Image Writer", "Image written successfully."); } else { Log.d("Image Writer", "Image write failed, but without an explanation."); } } catch (Exception e){ Log.d("Image Writer", "Problem with the image. Stacktrace: ", e); } </code></pre> <p>On my emulator running v1.5, that's successfully saves a bitmap onto the SD card in the DCIM/Camera folder with its file name being current time. (The time is saved in milliseconds since 1st Jan 1970, also known as the "Epoch" for some reason.)</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.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      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