Captura de imagem com câmera e upload para Firebase (Uri em onActivityResult () é nulo)

Então, eu tenho um problema, mencionado anteriormente na pergunta que fiz:Fazendo upload de imagem (ACTION_IMAGE_CAPTURE) no armazenamento Firebase

Pesquisei um pouco mais o problema e apliquei a documentação do Android Studio:https://developer.android.com/training/camera/photobasics.html#TaskPhotoView

Então, antes de ler o códigoBasicamente quero dizero que é preciso: Eu só quero capturar uma foto com a câmera e enviá-la diretamente para o armazenamento Firebase. Para fazer isso, preciso que o Uri contenha a foto que acabei de tirar (Uri.getLastPathSegment ()), mas ainda não consegui fazer isso.

Então agora, é assim que meu código se parece (apenas partes relacionadas):AndroidManifest.xml:

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.example.android.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/file_paths"></meta-data>
</provider>

Eu tenho ores / xml / file_paths.xml:

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
<external-path name="my_images"   path="Android/data/com.serjardovic.firebasesandbox/files/Pictures" />
</paths>

e finalmente oMainActivity.java:

public class MainActivity extends AppCompatActivity {

private Button b_gallery, b_capture;
private ImageView iv_image;
private StorageReference storage;
private static final int GALLERY_INTENT = 2;
private static final int CAMERA_REQUEST_CODE = 1;
private ProgressDialog progressDialog;

String mCurrentPhotoPath;

private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

private void dispatchTakePictureIntent() {
    Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    // 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...
        }
        // Continue only if the File was successfully created
        if (photoFile != null) {
            Uri photoURI = FileProvider.getUriForFile(this,
                    "com.example.android.fileprovider",
                    photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, CAMERA_REQUEST_CODE);
        }
    }
}


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    storage = FirebaseStorage.getInstance().getReference();

    b_gallery = (Button) findViewById(R.id.b_gallery);
    b_capture = (Button) findViewById(R.id.b_capture);
    iv_image = (ImageView) findViewById(R.id.iv_image);

    progressDialog = new ProgressDialog(this);

    b_capture.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            dispatchTakePictureIntent();

        }
    });
}

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

    if(requestCode == CAMERA_REQUEST_CODE && resultCode == RESULT_OK){
        progressDialog.setMessage("Uploading...");
        progressDialog.show();
        Uri uri = data.getData();

        StorageReference filepath = storage.child("Photos").child(uri.getLastPathSegment());
        filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
            @Override
            public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
                Toast.makeText(MainActivity.this, "Upload Successful!", Toast.LENGTH_SHORT).show();
                progressDialog.dismiss();
            }
        }).addOnFailureListener(new OnFailureListener() {
            @Override
            public void onFailure(@NonNull Exception e) {
                Toast.makeText(MainActivity.this, "Upload Failed!", Toast.LENGTH_SHORT).show();
            }
        });
        }
    }
}

Precisa de uma solução! Ainda assim, o aplicativo falha depois que eu tiro a foto e pressiono o botão de confirmação e recebo o seguinte relatório de falha:

java.lang.RuntimeException: falha ao entregar o resultado ResultInfo {who = null, request = 1, result = -1, data = null} para a atividade {com.serjardovic.firebasesandbox / com.serjardovic.firebasesandbox.MainActivity}: java.lang. NullPointerException: tentativa de chamar o método virtual 'android.net.Uri android.content.Intent.getData ()' em uma referência de objeto nulo

questionAnswers(2)

yourAnswerToTheQuestion