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