3

We are facing an issue for passing intent data to onActivityResult method when we start ACTION_IMAGE_CAPTURE intent getting null for intent

Here is my code for starting camera activity and passing data to the onActivityResult()

don't know whats went wrong strange please help me out

Thanks in adavnce

 public void takePicture()
    {
        File directory = new File(Environment.getExternalStorageDirectory() + "/AML_AttachmentImages" + "/");

        if (!directory.exists())
        {
            directory.mkdir();
        }

        int count = 0;
        if (directory != null)
        {
            File[] files = directory.listFiles();
            if (files != null)
            {
                count = files.length;
            }
        }
        count++;
        String imagePath = "AML_IMAGE_" + count + ".jpg";
        File file = new File(directory, imagePath);
        outputFileUri = Uri.fromFile(file);

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        startActivityForResult(intent, TAKE_PHOTO_CODE);

    }


 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data)
    {
        if (resultCode == RESULT_OK)
        {
            switch (requestCode)
            {
                case TAKE_PHOTO_CODE :
                    outputFileUri=data.getParcelableExtra(MediaStore.EXTRA_OUTPUT);
                    File imageFilePath = new File(outputFileUri.getPath());
                    imagePathUris.add(imageFilePath.getAbsolutePath());
                    Bitmap myBitmap = BitmapFactory.decodeFile(imageFilePath.getAbsolutePath());
                    bitmaps.add(myBitmap);
                    txtAttachmentsCount.setVisibility(View.VISIBLE);
                    txtAttachmentsCount.setText(getResources().getString(R.string.view_attachment_text) + Integer
                            .toString(imagePathUris.size()) + ")");

                    break;
                case REQ_PIC :
                    final ContentResolver cr = getContentResolver();
                    final String[] p1 = new String[]{MediaStore.Images.ImageColumns._ID,
                            MediaStore.Images.ImageColumns.DATE_TAKEN};
                    Cursor c1 = cr.query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, p1, null, null, p1[1] + " DESC");
                    if (c1.moveToFirst())
                    {
                        String uristringpic = "content://media/external/images/media/" + c1.getInt(0);
                        Uri newuri = Uri.parse(uristringpic);
                        Log.i("TAG", "newuri   " + newuri);

                    }
                    c1.close();

                    break;

            }
        }
    }
rciovati
  • 27,603
  • 6
  • 82
  • 101
kondal
  • 358
  • 1
  • 6
  • 22
  • Have you looked at [this question](http://stackoverflow.com/questions/11591243/accessing-camera-using-action-image-capture?rq=1) ? – David Wasser Apr 26 '13 at 14:17
  • When we call onActivityResult does my gloabl varibales value will be garbage collected i mean set to null? – kondal Apr 26 '13 at 14:28
  • I am able to pass intent if i remove the line intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); but how can i able to pass data to intent – kondal Apr 26 '13 at 14:30
  • So it looks like you are seeing the same bug that has been reported int he linked question. – David Wasser Apr 26 '13 at 14:31
  • What global variables are you referring to. Post the relevant code. – David Wasser Apr 26 '13 at 14:32

0 Answers0