0

I'm trying to get a picture from user during a registration proccess. So I have a form, and a button that starts camera, galerry, dropbox etc and asks user to choose or take a pic.

At the button onClick method I'm using the example at the 2nd answer of this topic Allow user to select camera or gallery for image and it opens a dialog with my image apps as options. After taking or choosing a foto, my code at onActivityResult is the following:

Bundle extras = data.getExtras();
Bitmap mImageBitmap = (Bitmap) extras.get("data");
foto.setImageBitmap(mImageBitmap)

So I have 2 problems. First, this get only a thumbnail image, and not the full-sized picture I need. Second, this only works if user chooses to take a new pic with camera...

for getting the fullsize pic, this code seems good Android Camera Intent: how to get full sized photo? but its only for camera-taken pics, and also with this chooser intent I'm not sure where this code would fit. Should I verify witch source use has choosed? If so, how could I do that?

EDIT: The chooser intent offers me 4 options of image sources: Camera, Gallery, Dropbox and ASTRO File Manager. Of course more options would be available if I had other apps installed. So I've checked the intent contents at each case:

CAMERA: act=inline-data (has extras)
DROPBOX and GALLERY: dat="file path"
ASTRO: dat="file path" (has extras)

so verifying if the intent has extras or not doesn't tells me the source. Also both data.hasExtra("act") and data.hasExtra("dat") are returning false.

Community
  • 1
  • 1
Lucas Jota
  • 1,863
  • 4
  • 24
  • 43
  • you should explore the content of the extras. there must be something there. – njzk2 Nov 19 '12 at 13:04
  • I guess any full sized image will be available from the intent. One solution, as showed at the 2nd link I've posted, is saving image on sdcard an than getting it back. Just can't figure out how to know wich source was selected from user. – Lucas Jota Nov 19 '12 at 13:16

1 Answers1

2

Here is the code for getting the full size image from camera captured image

declare object

private File dir, destImage,f;
private String cameraFile = null;

private static final int CAPTURE_FROM_CAMERA = 1;

in your activity

dir = new File(Environment.getExternalStorageDirectory()
            .getAbsolutePath(), "MyApp");
if (!dir.isDirectory())
    dir.mkdir();

destImage = new File(dir, new Date().getTime() + ".jpg");
cameraFile = destImage.getAbsolutePath();   
try{
    if(!destImage.createNewFile())
        Log.e("check", "unable to create empty file");

}catch(IOException ex){
    ex.printStackTrace();
}

f = new File(destImage.getAbsolutePath());
Intent i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(destImage));
startActivityForResult(i,CAPTURE_FROM_CAMERA);

in your onActivityResult

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    switch (requestCode) {
      case CAPTURE_FROM_CAMERA:
        if (resultCode==RESULT_OK) {
            if(f==null){
                if(cameraFile!=null)
                    f = new File(cameraFile);
                else
                    Log.e("check", "camera file object null line no 279");
            }else
                Log.e("check", f.getAbsolutePath());
            Bitmap useBitmap = BitmapFactory.decodeFile(f.getAbsolutePath());

                            // now use this bitmap wherever you want
        }
        break;
     }
}
Pratik
  • 30,639
  • 18
  • 84
  • 159
  • My code uses a chooserIntent to allow user to select the wanted source. So my onActivityResult should handle not only the (capture from camera) scenario, but also handle pictures selected from gallery, dropbox and other 3rd apps. This chooserIntent example is at the 2nd answer in this topic http://stackoverflow.com/questions/4455558/allow-user-to-select-camera-or-gallery-for-image – Lucas Jota Nov 19 '12 at 13:21