title: Capturing file gives null image in xiaomi red mi device
body: <p>I want to add code for capture image and select image from gallery. I have added it and worked on some devices like motorola and samsung. But when I tested on xiaomi red mi it crashed while capturing the image, filename returned null and for selecting image from gallery it dose not get selected the cursor returns null.</p>
  
  <pre><code>  private void selectImage() {
      final CharSequence[] items = { "Take Photo", "Choose from Library",
              "Cancel" };
  
      AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
      builder.setTitle("Add Photo!");
      builder.setItems(items, new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int item) {
  
  
                  if (items[item].equals("Take Photo")) {
                      userChoosenTask = "Take Photo";
  
                      result = Utility.checkAndRequestPermissions(RegisterActivity.this);
  
                      if (result) {
                          cameraIntent();
                      }
  
                  } else if (items[item].equals("Choose from Library")) {
                      userChoosenTask = "Choose from Library";
  
                      result = Utility.checkAndRequestPermissions(RegisterActivity.this);
  
                      if (result) {
                          galleryIntent();
                      }
  
                  } else if (items[item].equals("Cancel")) {
                      dialog.dismiss();
                  }
  
          }
      });
      builder.show();
  
  }
  
  
    private void galleryIntent()
  {
  
      Intent intent = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
  
      startActivityForResult(intent,SELECT_FILE);
  
  }
  
  private void cameraIntent()
  {
          Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
     if (intent.resolveActivity(getPackageManager()) != null) {
          // Create the File where the photo should go
          File photoFile = null;
          try {
              photoFile = createImageFile();
          } catch (IOException ex) {
              // Error occurred while creating the File
           //   UiUtils.showAlert(getString(R.string.error),NewGroupAcvitity.this);
          }
          // Continue only if the File was successfully created
          if (photoFile != null) {
             intent.putExtra(MediaStore.EXTRA_OUTPUT,
                      Uri.fromFile(photoFile));
              startActivityForResult(intent,REQUEST_CAMERA);
          }
      }
  
  }
  private File createImageFile() throws IOException {
      // Create an image file name
      String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
      String imageFileName = "image";
      File storageDir = Environment.getExternalStoragePublicDirectory(
              Environment.DIRECTORY_PICTURES);
      File image = File.createTempFile(
              imageFileName,  /* prefix */
              ".jpg",         /* suffix */
              storageDir      /* directory */
      );
  
      // Save a file: path for use with ACTION_VIEW intents
      fileName =  image.getAbsolutePath();
      return image;
  }
  
  public void loadImageFromFile(String imageFile){
  
      try {
          ExifInterface ei = new ExifInterface(imageFile);
          int orientation = ei.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                  ExifInterface.ORIENTATION_UNDEFINED);
  
          Bitmap bitmap = BitmapFactory.decodeFile(imageFile);
  
          Bitmap rotatedBitmap = null;
  
          switch (orientation) {
              case ExifInterface.ORIENTATION_ROTATE_90:
                  rotatedBitmap = rotateImage(bitmap, 90);
                  break;
              case ExifInterface.ORIENTATION_ROTATE_180:
                  rotatedBitmap = rotateImage(bitmap, 180);
                  break;
              case ExifInterface.ORIENTATION_ROTATE_270:
                  rotatedBitmap = rotateImage(bitmap, 270);
                  break;
              case ExifInterface.ORIENTATION_NORMAL:
              default:
                  rotatedBitmap = bitmap;
                  break;
          }
  
          if(rotatedBitmap != null)
          {
              profile_image.setImageBitmap(rotatedBitmap);
              selectedBitmap = rotatedBitmap;
  
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              selectedBitmap.compress(Bitmap.CompressFormat.PNG, 100, stream); //replace 100 with desired quality percentage.
              byte[] byteArray = stream.toByteArray();
  
                  File tempFile = File.createTempFile("temp",null, getCacheDir());
                  FileOutputStream fos = new FileOutputStream(tempFile);
                  fos.write(byteArray);
  
                  mProfileImage = tempFile;
          }
  
      }
      catch (IOException ex) {
        //  UiUtils.showAlert(getString(R.string.error),NewGroupAcvitity.this);
      }
  }
  
  public static Bitmap rotateImage(Bitmap source, float angle) {
      Matrix matrix = new Matrix();
      matrix.postRotate(angle);
      return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), matrix,
              true);
  }
  @Override
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
      super.onActivityResult(requestCode, resultCode, data);
  
      if (resultCode == Activity.RESULT_OK) {
          if (requestCode == SELECT_FILE)
              onSelectFromGalleryResult(data);
          else if (requestCode == REQUEST_CAMERA)
              onCaptureImageResult(data);
      }
  }
  
  private void onCaptureImageResult(Intent data) {
  
      loadImageFromFile(fileName);
  
  }
  
  @SuppressWarnings("deprecation")
  private void onSelectFromGalleryResult(Intent data) {
  
      Uri uri = (Uri)data.getData();
  
      Log.d("data", String.valueOf(data));
  
      String[] filePathColumn = { MediaStore.Images.Media.DATA };
      Cursor cursor = getContentResolver().query(uri,filePathColumn, null, null, null);
      if(cursor != null) {
          cursor.moveToFirst();
          int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
          String picturePath = cursor.getString(columnIndex);
          cursor.close();
          loadImageFromFile(picturePath);
      }
  }
  </code></pre>
  
  <p>Also it takes too much time to select or capture the image more than 10 seconds, what can be the reason?</p>
  
  <p>Can anyone help please? Thank you..</p>