0

Helo,

I have two activities A and B. in activity A I have a google map and a button. The button allow me to take a picture. after taking picture I want it in activity B where I can edit it and give title and so on.

this is my method in activity A wenn I click a button to take a picture

private void onTakeFoto() {


    Intent fotoIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    startActivityForResult(fotoIntent, CAMERA_RESULT);

}

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

    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {

        Intent intentB = new Intent(this, B.class);
        startActivityForResult(intentB , CAMERA_RESULT);

    }

}

in activity B I have an imageView and EditText. I want to show the captured image in the imageView in activty B. How can I do it? can someone give me a tip for that?

thanks

in my onActivityResult I now have this code:

String res = null;
        String[] proj = {MediaStore.Images.Media.DATA};
        Cursor cursor =  getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, null, null, null);
        if (cursor.moveToLast()) {
            int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
            res =  cursor.getString(column_index);
                            cursor.close();
                Bitmap bitMap = BitmapFactory.decodeFile(res);
                m_currentImage.setImageBitmap(bitMap);

        }

As I said I got other Image and not the captured one. Can sombody tell me where is the mistake?

ayahya82
  • 374
  • 3
  • 6
  • 18

4 Answers4

0

You can start camera in Activity B class and take the picture and set the picture on imageview.use this way...

@Override
    protected void onActivityResult(int requestCode, int resultCode,
            Intent resultData) {
        super.onActivityResult(requestCode, resultCode, resultData);



        try {

            if ( resultData != null) {

                String[] projection = { MediaStore.Images.Media.DATA };
                Cursor cursor = managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        projection, null, null, null);
                int column_index_data = cursor
                        .getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
                cursor.moveToLast();

                uploadImagePath = cursor.getString(column_index_data);
                bitmapUploadImage = BitmapFactory.decodeFile(uploadImagePath);
                profileImageView.setImageBitmap(bitmapUploadImage);
Sunil Kumar
  • 7,086
  • 4
  • 32
  • 50
0

You can pass the result of fotoIntent activity to the new B activity via putExtra

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307
0

One suggestion please do the decoding of image on other thread and not on UI Thread.

nikhil.thakkar
  • 1,093
  • 7
  • 12
0

Finally I found the answer,

 if (resultCode == RESULT_OK && requestCode == CAMERA_RESULT) {

        Bitmap captureImage = (Bitmap) data.getExtras().get("data");
        m_currentImage.setImageBitmap(captureImage);
  }
ayahya82
  • 374
  • 3
  • 6
  • 18