1

im build some apps that call camera activity..

im just to take picture from my apps and send it to web server..

but i can't get my image path..

im always getting NullException Error when try to get image path..

here's my code when calling camera activity :

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    this.startActivityForResult(camera, PICTURE_RESULT);

and this is code for activity result :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == PICTURE_RESULT){
        if (resultCode == Activity.RESULT_OK) {
            takePicture(data);
        } else if (resultCode == Activity.RESULT_CANCELED) {

        }
    }
}

protected void takePicture(Intent data) {
    Bundle b = data.getExtras();
    pic = (Bitmap) b.get("data");
    if (pic != null) {
        imagePicture.setImageBitmap(pic);
    }
}

is there something wrong with my code?

Thanks

pensilhijau
  • 193
  • 3
  • 4
  • 17

1 Answers1

2

Ok, I see your problem. You're not setting the path to begin with. Please look at this doc.

http://developer.android.com/reference/android/provider/MediaStore.html#ACTION_IMAGE_CAPTURE

So you see, when you call ACTION_IMAGE_CAPTURE you are not passing it the extra EXTRA_OUTPUT that tells the application where the picture is going to be stored. This EXTRA_OUTPUT is the path to the file.

So right under where you make the intent do this:

Intent camera = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
URI pictureUri = Uri.fromFile(new File(<path to your file>));
camera.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
Otra
  • 8,108
  • 3
  • 34
  • 49