Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getoutputmediafileuri method is not accessible?

I'm learning how to take a picture and save it's path into a file.

According to the tutorials offers on android developers website, the method

getoutputmediafileuri() is used, however, when I tried to use that method, i found that it's

not accessible or undefined, i mean eclipse underlines this method with redline. I don't know

how to fix this error.

Please find below the code

public class SaveCameraImageDemoActivity extends Activity {
/** Called when the activity is first created. */

Button btn01;
private Uri fileURI;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    btn01 = (Button) findViewById(R.id.btn01);
    btn01.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub

            Intent intenet = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            fileURI = getoutputmediafileuri();
            //intenet.putExtra("output", uri.getPath());
            startActivityForResult(intenet,0);
        }
    });
}

protected void onActivityResult(int requestCode, int resultCode, Intent data) {

  }
}
like image 501
Androelpha Avatar asked Mar 21 '12 09:03

Androelpha


2 Answers

There is no inbuilt method getoutputmediafileuri() in android. It is a custom method someone write for getting file URI to store captured images in particular directory. You have to defined and put logic for it. Instead of that use this code,

EDIT:

btn01.setOnClickListener(new OnClickListener() {
   @Override
    public void onClick(View v) {

       Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
       File imagesFolder = new File(Environment.getExternalStorageDirectory(), "MyImages");
       imagesFolder.mkdirs(); // <----
       File image = new File(imagesFolder, "image_001.jpg");
       Uri uriSavedImage = Uri.fromFile(image);
       imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
       startActivityForResult(imageIntent,0);
  }
});

Now this will store your camera captured images in MyImages directory in sdcard with image_001.jpg name.

like image 174
user370305 Avatar answered Oct 07 '22 09:10

user370305


The getoutputmediafileuri() method is defined here: http://developer.android.com/guide/topics/media/camera.html#saving-media

like image 29
Jeff Buck Avatar answered Oct 07 '22 10:10

Jeff Buck