-1

I'm trying to do an app (with the master/detail flow template) that in the detail fragment, has an ImageView that shows an image taken by the camera.

For this option, I added a button to the ActionBar that opens a Dialog box and asks the user if he wishes to add an image with the camera. So for this option I made this two methods that are called when the user clicks ok. However, (here I now I'm making huge mistakes) I don't have the least idea about how to call the onActivityResult() with the end of having my ImageIcon showing the thumbnail retrieved from the camera. (as developer.android tutorial shows)

If anyone of you guys knows what I am doing wrong, I would be really happy to hear all the solutions that you can give me, since I wasn't able to find a solution to this problem anywhere.

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
        onActivityResult(REQUEST_IMAGE_CAPTURE, RESULT_OK, takePictureIntent);
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode == RESULT_OK) {
        Bundle extras = data.getExtras();
        Bitmap imageBitmap = (Bitmap) extras.get("data");
        ImageView mImageView = (ImageView) findViewById(R.id.imageView1);
        mImageView.setImageBitmap(imageBitmap);
    }
}

THANKS A LOT!!!!

kickingnico
  • 178
  • 1
  • 11

3 Answers3

0

You have to create a scaled bitmap from the bitmap received in onActivityResult. You will get information about how to create a scaled bitmap Here

Community
  • 1
  • 1
Pankaj Deshpande
  • 502
  • 2
  • 5
  • 15
  • thanks a lot for answering, but i think i have gotten the bitmap, however i can't implement the method because i'm not sure what to put on the arguments. idk if im getting you right – kickingnico Jan 02 '15 at 06:02
  • Read this article , you will get the answer http://developer.android.com/training/displaying-bitmaps/load-bitmap.html – Pankaj Deshpande Jan 02 '15 at 13:19
0

You can set the width and height as desired

imageBitmap = Bitmap.createScaledBitmap(realImageBitmap, final_width, final_height, false);
imageView.setImageBitmap(imageBitmap);
Sumighosh Charuvil
  • 446
  • 1
  • 4
  • 14
0

You do not have to call onActivityResult explicitly. onActivityResult method called in the parent activity when the immediately child/successor activity finished its task. So when your Image taking activity will finished the task it call automatically a "requestCode" and Image data(If your Image taking activity take a picture otherwise it will be null). For more details about the onActivityResult see the here.

To set the thumbnail to the imageview you can do this in the following way.

Bitmap photo = (Bitmap) data.getExtras().get("data"); 
imageView.setImageBitmap(photo);

You can see this tutorial about the how to take Image using intent.

Happy Coding

BeingMIAkashs
  • 1,375
  • 11
  • 18
  • Thanks a lot BeingMlAkashs, you solved my question perfectly with something I think must be very basic, I'm not very familiar with overriding, so I really thank you for this solution. I can finally add my pictures!!!!! Thanks a lot – kickingnico Jan 02 '15 at 07:01