Search code examples
androidcrashcamerasaveonactivityresult

Android crashing when i take a picture on a real samsung galaxy s3


i made an application that will allow the user to take a camera shot and edit it using my application. I own a samsung galaxy stellar and it works fine on it. I had my friend download the application and when she tested it on her phone, my application crashes whenever she takes a picture and hit "save". shes using a galaxy s3.

Heres my code when im taking a picture

case R.id.ibTakePic:

i = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);

File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)+File.sep    arator + fileName2 + ".jpg");
i.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(file));
rotatePic = true;
startActivityForResult(i,cameraData);
break;

and heres my result code..

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

     if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
            Uri selectedImage = data.getData();
            String[] filePathColumn = { MediaStore.Images.Media.DATA };
            pictake = true;
            Cursor cursor = getContentResolver().query(selectedImage,
                    filePathColumn, null, null, null);
            cursor.moveToFirst();

            int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
            String picturePath = cursor.getString(columnIndex);
            cursor.close();
            rotatePic = false;
            bmpReceive = rotate(picturePath);

            bmpOriginal = bmpReceive; 

            picTaken.setImageBitmap(bmpReceive);
   //         ImageView imageView = (ImageView) findViewById(R.id.imgView);
     //       imageView.setImageBitmap(BitmapFactory.decodeFile(picturePath));


        }

Solution

  • I had a similar problem so I switched to this:

    Uri uri= data.getData();
    InputStream in = context.getContentResolver().openInputStream(uri);
    Bitmap b = BitmapFactory.decodeStream(in);
    

    hope it helps