1

i have my bitmap and I want to convert my bitmap to save as image in another new file by below code.

Note: Its Working fine in all devices Except Galaxy S3. can any one help me to make this code workable in S3. i always getting this Toast while converting to new file. anyone have idea what the problem might occurring.

Bitmap photo = (Bitmap) extras.get("data");

                selectedImagePath = String.valueOf(System.currentTimeMillis())
                        + ".jpg";

                Log.i("TAG", "new selectedImagePath before file "
                        + selectedImagePath);

                File file = new File(Environment.getExternalStorageDirectory(),
                        selectedImagePath);

                try {
                    file.createNewFile();
                    FileOutputStream fos = new FileOutputStream(file);
                    photo.compress(Bitmap.CompressFormat.PNG, 95, fos);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    Toast.makeText(this,
                            "Sorry, Camera Crashed-Please Report as Crash A.",
                            Toast.LENGTH_LONG).show();
                }

Thanks in Advance.

1
  • 2
    What is the value of e.getMessage()? Commented Jan 29, 2013 at 14:29

1 Answer 1

2

It is possible the storage is not in a state to be written to, there are a number of reason this could happen. You should be checking getExternalStorageState prior to accessing the external storage. Even if it is not happening on other devices, it could happen, so best to guard against it.

If external storage is MEDIA_MOUNTED, and your problem still persists, you can get a better handle on what is happening by looking at what caused your exception by adding e.getMessage() to your Toast or logs.

You also appear to be using the top-level directory for storing your files. This should not cause a technical problem, but is considered best to create a subdirectory for your app and store files there. From the getExternalStorageDirectory docs --

Applications should not directly use this top-level directory, in order to avoid polluting the user's root namespace.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.