0

Thia code crashes when i took a photo from camera. but when i pick a photo from gallery it works fine. please guide me. I debug this code. the value of data is getting null when i took a picture from camera

@Override
        public void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);

            if (resultCode == Activity.RESULT_OK || requestCode == 200||requestCode==CAMERA_REQUEST) {
                Glide.with(this).load(data.getData()).into(mDishUploadImg);

                Bitmap bm = null;
                try {
                    bm = MediaStore.Images.Media.getBitmap(mainActivity.getContentResolver(), data.getData());
                } catch (IOException e) {
                    e.printStackTrace();
                }
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                bm.compress(Bitmap.CompressFormat.JPEG, 50, baos); //bm is the bitmap object
                byte[] b = baos.toByteArray();
                base64img = Base64.encodeToString(b, Base64.NO_WRAP);
            }
        }
GianhTran
  • 3,443
  • 2
  • 22
  • 42

1 Answers1

0

Try Adding data!=null && data.getData() != null into your if Statement and also instead of using || use &&.

Gourav
  • 2,746
  • 5
  • 28
  • 45
Hassam Talha
  • 47
  • 1
  • 10