2

My app involves selecting an image from the device's gallery and then saving a smaller version of that image to a folder on the SD Card. The problem I'm running into is that some users are reporting that the images aren't getting saved to the folder. Most users, however, report that the app is working fine and I can't tell what is happening to these other few users. So far, the devices that are reported to be running into the issue are as follows: Huawei T-Mobile myTouch, Samsung GT-S5830i, HTC Evo 4G, and the Samsung Galaxy S2. I myself have a Motorola Atrix 2 and I've had no such issue.

My manifest has the tag in it already. Most of my code comes from other stackoverflow solutions to get an image from the gallery and then save it to the sd card.

Getting image from gallery:

public void onActivityResult(int requestCode, int resultCode, Intent data) 
{
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) 
    {
         switch(requestCode) 
         {
            case SELECT_IMAGE:
                 image_dir = getPath(data.getData());

                 Bitmap myBitmap = decodeFile(new File(image_dir));

                 resizedBitmap = Bitmap.createScaledBitmap(myBitmap, (int)(myBitmap.getWidth()/2), (int)(myBitmap.getHeight()/2), true);
                 break;
         }
    }
    else
    {
         image_dir = "None";
    }
}

Saving the image to the SD Card:

OutputStream fOut = null;
File file = new File(Environment.getExternalStorageDirectory()+"/MyApp",imgname+".jpg");
fOut = new FileOutputStream(file);

resizedBitmap.compress(Bitmap.CompressFormat.JPEG, 100, fOut);
fOut.flush();
fOut.close();

And this all seems to work out fine for most users, but for some users the image isn't getting saved. Could this be a permissions issue or some sort of setting I've overlooked in the code itself? Any help is appreciated.

user
  • 86,916
  • 18
  • 197
  • 190
Kyle D
  • 21
  • 1

2 Answers2

0

according to this,

This directory may not currently be accessible if it has been mounted by the user on their computer, has been removed from the device, or some other problem has happened

Environment.getExternalStorageDirectory() will return null, so you should check Environment.getExternalStorageState() first.

jaredzhang
  • 1,158
  • 8
  • 12
0

The reason may be that these devices dont use the popular external storage convention /mnt/sdcard/ . Here are some hints that this is the case for Samsung Galaxy S2 and for HTC Evo 4G. Probably the problem is not that the SD is not mounted, but you should definetely run that check as suggested by jaredzhang. I would also suggest listening for the most probable errors and reporting them - for example, check if SD is mounted, if target folder exists etc. Needless to say, it would be best to get your hands on one of those devices and to check for yourself. Perhaps you can also search online for what is the result getExternalStorageDirectory() for those devices.

Community
  • 1
  • 1
ılǝ
  • 3,440
  • 2
  • 33
  • 47