3

I have developed a camera application with default camera. This application works in all other Android phones but some problem with Samsung Galaxy S

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

This code is giving a result and I am getting a bitmap image. But I couldn't retrieve an image path from this.

When I give EXTRA_OUTPUT, Galaxy S returning a null value. So that I couldn't define file path and name before calling camera intent. When we take picture using this application, Galaxy S is saving this picture in default location and not saving to pre defined location.

If anybody has solution for this, please help me.

Tester101
  • 8,042
  • 13
  • 55
  • 78

2 Answers2

0

Found answer here is the best example which is it self bothering about the device!

AndroidCameraUtils - Download the project and from library project by including it below is the code snippet you can use !

 private void setupCameraIntentHelper() {
    mCameraIntentHelper = new CameraIntentHelper(this, new CameraIntentHelperCallback() {
        @Override
        public void onPhotoUriFound(Date dateCameraIntentStarted, Uri photoUri, int rotateXDegrees) {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_found) + photoUri.toString());

            Bitmap photo = BitmapHelper.readBitmap(CameraIntentActivity.this, photoUri);
            if (photo != null) {
                photo = BitmapHelper.shrinkBitmap(photo, 300, rotateXDegrees);
                ImageView imageView = (ImageView) findViewById(de.ecotastic.android.camerautil.sample.R.id.activity_camera_intent_image_view);
                imageView.setImageBitmap(photo);
            }
        }

        @Override
        public void deletePhotoWithUri(Uri photoUri) {
            BitmapHelper.deleteImageWithUriIfExists(photoUri, CameraIntentActivity.this);
        }

        @Override
        public void onSdCardNotMounted() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sd_card_not_mounted), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCanceled() {
            Toast.makeText(getApplicationContext(), getString(R.string.warning_camera_intent_canceled), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onCouldNotTakePhoto() {
            Toast.makeText(getApplicationContext(), getString(R.string.error_could_not_take_photo), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onPhotoUriNotFound() {
            messageView.setText(getString(R.string.activity_camera_intent_photo_uri_not_found));
        }

        @Override
        public void logException(Exception e) {
            Toast.makeText(getApplicationContext(), getString(R.string.error_sth_went_wrong), Toast.LENGTH_LONG).show();
            Log.d(getClass().getName(), e.getMessage());
        }
    });
}

@Override
protected void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    mCameraIntentHelper.onSaveInstanceState(savedInstanceState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);
    mCameraIntentHelper.onRestoreInstanceState(savedInstanceState);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    super.onActivityResult(requestCode, resultCode, intent);
    mCameraIntentHelper.onActivityResult(requestCode, resultCode, intent);
}
}
  • Add below lined to manifest file of your activityandroid:configChanges="keyboardHidden|orientation|screenSize"

NOTE:- I tried many examples for camera utils and ofcourse there are another ways to handle it but for beginners and person who are not too much familier with the core concepts would be more comfort with this project. THanks!

Hardy
  • 2,576
  • 1
  • 23
  • 45
0

What I've done for this is define a location for EXTRA_OUTPUT as a Uri, cache that in a static or member variable, and then in onActivity result use the cached location to retrieve the image. I had the same problem you were describing, and this seems to work fine. The only drawback is having 2 copies of the image, one in the location you defined in EXTRA_OUTPUT, and one in the default location.

jvergeldedios
  • 637
  • 1
  • 6
  • 15
  • Yes. But i have to avoid duplicate copy. The application like foursquare is giving same features without image duplication. – Shani L Ganga Oct 18 '11 at 06:57
  • There is an approach outlined [here](http://pixelsystems.net/?page_id=79) that attempts to do what you describe. Basically you will be listening for a new Gallery image, copying it to the location you want, then deleting the record from the media store. This way you end up with only one image. – jvergeldedios Oct 18 '11 at 07:41
  • He also has a Github account with his example code [here](https://github.com/pr0cs/CameraTest). – jvergeldedios Oct 18 '11 at 07:42