0

I have an android app that start the smartphone camera

Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST );

To display the taken picture I use this piece of code,

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    setImage=true;
    if (requestCode == CAMERA_PIC_REQUEST && resultCode == RESULT_OK) {
        if(data!=null)
        {
            ImageView image = (ImageView) findViewById(R.id.imagePreview);
            Bundle extras = data.getExtras();
             Bitmap mImageBitmap = (Bitmap) extras.get("data");
             image.setImageBitmap(mImageBitmap);
        }
   }
}

This works pretty fine but if i want to get the path of the taken picture, i have to use (intent)data.getData() but this returns a null value. what should i do to solve this problem?

D. Wonnink
  • 306
  • 4
  • 19
Dennis
  • 143
  • 5
  • 17

2 Answers2

0

Try out as below:

      Bitmap m_photo = (Bitmap) p_data.getExtras().get("data");
    if (m_photo != null)
    {
    ByteArrayOutputStream m_upByteArrayOutputStream = new ByteArrayOutputStream();
    m_photo.compress(Bitmap.CompressFormat.PNG, 40, m_upByteArrayOutputStream);
    Drawable m_imageFromCamera = new BitmapDrawable(m_photo);
             image.setBackgroundDrawable(m_photo);
      }

EDITED:

To get the Path of the image try out below code:

     Uri selectedImage = data.getData();
        String[] filePathColumn = { MediaStore.Images.Media.DATA };
        Cursor cursor = getContentResolver().query(selectedImage,
                filePathColumn, null, null, null);
        cursor.moveToFirst();
        int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
        String imagePath = cursor.getString(columnIndex); <---- Here is your image path.
        cursor.close();
GrIsHu
  • 29,068
  • 10
  • 64
  • 102
0

Try this hope it helps you.

Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };

            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();

            String imageName = picturePath.substring(picturePath.lastIndexOf(
                    "/", picturePath.length()));
Hasham
  • 455
  • 4
  • 11