13

Problem: I am getting camera intent's data null in onActivityResult(int requestCode, int resultCode, Intent data) in Samsung S3. But working well on some other devices. I customized my code for getting data and searched this issue in web but nothing found useful.

Code :

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

    if (requestCode == TAKE_CAMERA && data != null && data.getData() != null)  

           else if (requestCode == TAKE_CAMERA) {
        if (resultCode != RESULT_OK) return;
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(tempFileUri, "image/*");

        intent.putExtra("outputX", 90);
        intent.putExtra("outputY", 90);
        intent.putExtra("aspectX", 1);
        intent.putExtra("aspectY", 1);
        intent.putExtra("scale", true);
        intent.putExtra("return-data", true);
        startActivityForResult(intent, CROP_CAMERA);
    } else if (requestCode == CROP_CAMERA && data != null) {
        Bitmap photo = data.getExtras().getParcelable("data");
        try {
            FileOutputStream out = new FileOutputStream(tempFileUri.getPath());
            photo.compress(Bitmap.CompressFormat.JPEG, 90, out);
        } catch (FileNotFoundException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        if (photo != null) {
            imagePhoto.setImageBitmap(photo);

            <my code>
        }

    }
Akhilesh Mani
  • 3,502
  • 5
  • 28
  • 59
  • Put your LOGCAT data here. I had facing same issues with s3 before it will fix through putting This permission in AndroidMenifest.xml file `` – user1621629 Jan 31 '13 at 16:06
  • unfortunately am not getting any log cat when image not loads. There is also sd card permission in my Menifest. – Akhilesh Mani Feb 01 '13 at 06:52

4 Answers4

3

if you are providing MediaStore.EXTRA_OUTPUT, then the intent is null, but you will have the photo in the file you provided (Uri.fromFile(f)).

I hope below link give the solution for you.It working for me.

http://mylearnandroid.blogspot.in/2014/02/multiple-choose-custom-gallery.html

2

I have Faced the Same Issue and got Work around with Below Way it will definitely help you tr it out once :

For the Solution i have referred below link for solve the issue :

Camera Solution for Samsung Galaxy S3

Write the Below Code While calling captured image :

Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, PICK_FROM_CAMERA);

And Get your URI by Below way inside OnActivityResult() Method:

if (resultCode != RESULT_OK)
            return;

        switch (requestCode) {
        case PICK_FROM_CAMERA:
            Log.i("TAG", "Inside PICK_FROM_CAMERA");


            // Describe the columns you'd like to have returned. Selecting from
            // the Thumbnails location gives you both the Thumbnail Image ID, as
            // well as the original image ID

            try {
                Log.i("TAG", "inside Samsung Phones");
                String[] projection = {
                        MediaStore.Images.Thumbnails._ID, // The columns we want
                        MediaStore.Images.Thumbnails.IMAGE_ID,
                        MediaStore.Images.Thumbnails.KIND,
                        MediaStore.Images.Thumbnails.DATA };
                String selection = MediaStore.Images.Thumbnails.KIND + "=" + // Select
                                                                                // only
                                                                                // mini's
                        MediaStore.Images.Thumbnails.MINI_KIND;

                String sort = MediaStore.Images.Thumbnails._ID + " DESC";

                // At the moment, this is a bit of a hack, as I'm returning ALL
                // images, and just taking the latest one. There is a better way
                // to
                // narrow this down I think with a WHERE clause which is
                // currently
                // the selection variable
                Cursor myCursor = this.managedQuery(
                        MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                        projection, selection, null, sort);

                long imageId = 0l;
                long thumbnailImageId = 0l;
                String thumbnailPath = "";

                try {
                    myCursor.moveToFirst();
                    imageId = myCursor
                            .getLong(myCursor
                                    .getColumnIndexOrThrow(MediaStore.Images.Thumbnails.IMAGE_ID));
                    thumbnailImageId = myCursor
                            .getLong(myCursor
                                    .getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
                    thumbnailPath = myCursor
                            .getString(myCursor
                                    .getColumnIndexOrThrow(MediaStore.Images.Thumbnails.DATA));
                } finally {
                    // myCursor.close();
                }

                // Create new Cursor to obtain the file Path for the large image

                String[] largeFileProjection = {
                        MediaStore.Images.ImageColumns._ID,
                        MediaStore.Images.ImageColumns.DATA };

                String largeFileSort = MediaStore.Images.ImageColumns._ID
                        + " DESC";
                myCursor = this.managedQuery(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        largeFileProjection, null, null, largeFileSort);
                String largeImagePath = "";

                try {
                    myCursor.moveToFirst();

                    // This will actually give yo uthe file path location of the
                    // image.
                    largeImagePath = myCursor
                            .getString(myCursor
                                    .getColumnIndexOrThrow(MediaStore.Images.ImageColumns.DATA));
                    mImageCaptureUri = Uri.fromFile(new File(
                            largeImagePath));

                } finally {
                    // myCursor.close();
                }
                // These are the two URI's you'll be interested in. They give
                // you a
                // handle to the actual images
                Uri uriLargeImage = Uri.withAppendedPath(
                        MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        String.valueOf(imageId));
                Uri uriThumbnailImage = Uri.withAppendedPath(
                        MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                        String.valueOf(thumbnailImageId));

                // I've left out the remaining code, as all I do is assign the
                // URI's
                // to my own objects anyways...
            } catch (Exception e) {

                Log.i("TAG",
                        "inside catch Samsung Phones exception " + e.toString());

            }


            try {

                Log.i("TAG", "URI Normal:" + mImageCaptureUri.getPath());
            } catch (Exception e) {
                Log.i("TAG", "Excfeption inside Normal URI :" + e.toString());
            }

            //doCrop();

            break;
Bhavesh Patadiya
  • 25,740
  • 15
  • 81
  • 107
  • @Akhilesh Mani: got the Solution? – Bhavesh Patadiya Feb 01 '13 at 04:51
  • Hi Bhavesh this not working in my side. After capturing image image, mobile orientation changes automatically and my uri gets null. I also stored that uri externally but this also not working. – Akhilesh Mani Feb 01 '13 at 07:35
  • @AkhileshMani: have you set inside menifest file this line 'android:configChanges="keyboardHidden|orientation"' for that activity and if not add it and also call onConfiguratiochanged() method for it. – Bhavesh Patadiya Feb 01 '13 at 09:09
  • you can look [Here](http://stackoverflow.com/questions/14495304/camera-force-closing-issue-in-samsung-galaxy-s3-version-4-1-1/14640678#14640678) my answer with full java file. you will better idea there. – Bhavesh Patadiya Feb 01 '13 at 09:14
1

I've solved this problem by telling the camera activity to save the image on SD card:

tempImageNameUri = "some temporary name";
i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
i.putExtra(MediaStore.EXTRA_OUTPUT,tempImageNameUri);
i.putExtra("return-data", true);
startActivityForResult(i,SOME_CONSTANT);

and when the called activity finished, in onActivityResult take the item from SD card from the temporary path and use it.

Axarydax
  • 16,353
  • 21
  • 92
  • 151
0

You might have got the solution to your question but this would help someone. Below is the blog link created by Commonsware which is about cropping of image after photo is taken. In which he said using action com.android.camera.action.CROP might not work perfect in all different kind of devices.

Here is the Link

Nav
  • 467
  • 4
  • 18