When I try to make a photo in onActivityRsult I get a NullPointerExaption when I retrieve data from the intent, while the photo is saved but I get a message that an error has occurred, it turns out that Intent data == null . I do on the tutorial from off.site, I can not understand where I was wrong.

  private void callCameraApp(){ Uri fileUri; // create Intent to take a picture and return control to the calling application Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); fileUri = CameraHelper.getOutputMediaFileUri(CameraHelper.MEDIA_TYPE_IMAGE); // create a file to save the image intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri); // set the image file name Log.e(TAG, "fileUri: " + fileUri); // start the image capture Intent startActivityForResult(intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE); } private void extractCaptureImage(int requestCode, int resultCode, Intent data) { Log.e(TAG, "Intent data: " + data); if (requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE && resultCode == Activity.RESULT_OK && null != data) { // Image captured and saved to fileUri specified in the Intent Toast.makeText(this, "Image saved to:\n" + data.getData(), Toast.LENGTH_LONG).show(); }else if (resultCode == RESULT_CANCELED) { // User cancelled the image capture Toast.makeText(this, "User cancelled the image capture", Toast.LENGTH_LONG).show(); } else { // Image capture failed, advise user Toast.makeText(this, "Image capture failed", Toast.LENGTH_LONG).show(); } } 

Logs:

 Log.e(TAG, "Intent data boolean: " + (data == null)); //true Log.e(TAG, "Intent data object: " + data); //null 
  • Under debug view your data. Here you need to know for sure whether it is null or not - Android Android
  • Just maybe a bitmap is sent to the date - Android Android
  • I added question results - Kirill Stoianov
  • You are not using the Camera API - Vladyslav Matviienko
  • @metalurgus corrected - CameraApp, you know what could be the problem? - Kirill Stoianov

1 answer 1

Solution to the problem:

The reason why the Intent does not return anything in this line intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri) . Specifying the parameter MediaStore.EXTRA_OUTPUT and the file in which you want to save the photo - the photo is saved automatically and accordingly nothing is returned, if the intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri) line intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri) is commented out, then the Bitmap will be returned in Intent and it will need to be saved manually.