开发者

Image wont save on different android devices

I am using this code to save a bitmap image taken from a screen shot:

try{
    String fname = "/Pictures/YourApp/YourPic.jpg";
    File path= Environment.getExternalStorageDirectory();
    File file = new File(path, fname);
    if (file.exists()) {
                Bitmap bitty = BitmapFactory.decodeFile(file.toString());
                    yourPlan.setImageBitmap(bitty); //ImageView
            }else{
                errorText.setText("If you can not see your image then free up some memory");
            }
        }catch(Exception e){
                errorText.setText("If you can not see your image then free up some memory");
        }

It works fine on my testing phone - an Orange San Francisco on 2.1 but I have had emails from users telling me they only get the error mes开发者_JAVA百科sage when saving with enough space.

They are using HTC and Samsung handsets. Any ideas?


First, I would like to point out that catching a general Exception e is not in good coding practice. Second, both messages you output to the user are also not helpful as it is not guaranteed that the error is space-related.

I am guessing the error comes from the file not existing. Where are you saving the file? From the snippet of code, I see that you are simply assuming the file exists. If you haven't yet saved the file after taking your screen shot, that would be your problem right there. You are opening a file that doesn't exist and your error message is giving the mistaken impression that there isn't enough space.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜