Only Samsung Android Camera Intent returns data null in landscape mode

Viewed 19

I am using a Samsung Android System camera to capture images, in that I got null image data in onActivityResult while it was captured in landscape mode but works well in portrait mode.

Note: The orientation of the Activity I used is Portrait.

Code:

private void openCameraIntent() {
    boolean hasGps = getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA);
    if (hasGps) {

        Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        List<ResolveInfo> resolvedIntentActivities = getPackageManager().queryIntentActivities(takePictureIntent, PackageManager.MATCH_DEFAULT_ONLY);

        // Ensure that there's a camera activity to handle the intent
        if (takePictureIntent.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
                ex.printStackTrace();
            }
            // Continue only if the File was successfully created
            if (photoFile != null) {
                Uri photoURI = FileProvider.getUriForFile(this,
                        "com.vcs.ecp.provider",
                        photoFile);
                for (ResolveInfo resolvedIntentInfo : resolvedIntentActivities) {
                    String packageName = resolvedIntentInfo.activityInfo.packageName;
                    grantUriPermission(packageName, photoURI, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
                }
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
            }
        }
    } else {
        Crouton.makeText(DoctorVisit.this, getString(R.string.device_unsupported), Style.ALERT).show();
    }
}

private File createImageFile() throws IOException {
    String dateInString = new SimpleDateFormat("ddMMyyyy").format(new Date());
    String imageFileName = User_NAME + "_" + intDrGlcode + "_" + dateInString + "_" + randomNo;
    File storageDir = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)));
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

onActivityResult:

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == REQUEST_TAKE_PHOTO) {
      if (resultCode == Activity.RESULT_OK) {
          if (mCurrentPhotoPath != null && !mCurrentPhotoPath.equalsIgnoreCase("")) {
              ArrayList<String> photoPaths = new ArrayList<>();
              photoPaths.add(mCurrentPhotoPath);
              manageFileSize(photoPaths);
          }
      }
    }
}

Here Intent data & mCurrentPhotoPath both are blank in landscape mode.

0 Answers
Related