12

Possible Duplicate:
Android Camera - Save image into a new folder in SD Card

i'm trying to take picture and save it to a file. The problem cames i'm trying to save the bitmap to a file. Here is my code:

private void takePic() {
    Intent cameraIntent = new Intent(
            android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
    startActivityForResult(cameraIntent, 2);


}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 2) {
            Bitmap photo = (Bitmap) data.getExtras().get("data");
            ImageView test = (ImageView) findViewById(R.id.test);
            test.setImageBitmap(photo);

            try {
                FileOutputStream out = new FileOutputStream("filename");
                photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

And the exceptions in logcat:

04-02 14:46:51.975: W/IInputConnectionWrapper(2225): showStatusIcon on inactive InputConnection
04-02 14:46:56.135: W/System.err(2225): java.io.FileNotFoundException: /filename (Read-only file system)
04-02 14:46:56.135: W/System.err(2225):     at org.apache.harmony.luni.platform.OSFileSystem.open(Native Method)
04-02 14:46:56.145: W/System.err(2225):     at dalvik.system.BlockGuard$WrappedFileSystem.open(BlockGuard.java:232)
04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.<init>(FileOutputStream.java:94)
04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.<init>(FileOutputStream.java:165)
04-02 14:46:56.145: W/System.err(2225):     at java.io.FileOutputStream.<init>(FileOutputStream.java:144)
Community
  • 1
  • 1
Worker123
  • 595
  • 4
  • 13
  • 32

1 Answers1

4

your error clearly says that java.io.FileNotFoundException: /filename

please provide exact path "/sdcard/filename"

new FileOutputStream(getExternalStorageDirectory()+"filename");

OR

String imageFilePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/name.png";

note: add permission WRITE_EXTERNAL_STORAGE in manifest file.

Never Quit
  • 2,072
  • 1
  • 21
  • 44
Mohammed Azharuddin Shaikh
  • 41,633
  • 14
  • 96
  • 115