views:

190

answers:

0

I wrote an application that takes picture from the camera. I use the native camera application by providing an Uri. When the user has taken the picture and goes back to the application screen, the Bitmap image is null. I dont't know why , it works well on HTC dream/g1 (android 1.5), Nexus One (android 2.1) and motorola milestone/droid (android 2.0.1) but on HTC tattoo (android 1.6) , it doesn't work!

here is the code to show the camera application (pictureUri : class attribute for the callback to retrieve the bitmap):

private void showNativeTakePictureApplication(){
    Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

    ContentValues values = new ContentValues();
    values.put(Media.TITLE, "a title");
    values.put(Media.DESCRIPTION, "a description");
    pictureUri = null;
    try {
        pictureUri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI, values); 
    } catch(UnsupportedOperationException e){
        try{
            pictureUri = getContentResolver().insert(Media.INTERNAL_CONTENT_URI, values); 
        }catch(UnsupportedOperationException e2){
            e2.printStackTrace();
        }
    }

    if (pictureUri == null) {
        Toast.makeText(this, "can not take picture", Toast.LENGTH_SHORT).show();
    } else {            
        intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri);
        startActivityForResult(intent, REQUEST_TAKE_PICTURE);
    }
}

here is the callback method called by onActivityResult():

private void onPictureTaken() {
    Bitmap selectedBitmap = null;
    try {
        selectedBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);

        selectedBitmap = ImageManager.resize(selectedBitmap);

        ImageLoader.saveImage(pictureUri.toString(), selectedBitmap);

    } catch (Exception e) {
        e.printStackTrace();
        Toast.makeText(this, "not saved", Toast.LENGTH_SHORT).show();   
    } finally {
        if (selectedBitmap != null) {
            selectedBitmap.recycle();
        }
        selectedBitmap = null;
    }
}

on HTC tattoo the selectedBitmap is null after the line

selectedBitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), pictureUri);