I have an onActivityResult, with two Case, one to choose an image from the Gallery, show it in the activity and then upload it to Firebase, all right here, then the other Case is to be able to take a photo with the camera and the sample, I tried to insert the code for tmb to upload that photo from the camera to FireBase but it does not work. Is it different from what I have in the case of the Gallery?
Code onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK){
switch (requestCode){
case PHOTO_CODE:
MediaScannerConnection.scanFile(this, new String[] { mPath }, null, new MediaScannerConnection.OnScanCompletedListener() {
@Override
public void onScanCompleted(String path, Uri uri) {
Log.i("ExternalStorage", "Scanned" + path + ":");
Log.i("ExternalStorage", "-> Uri = " + uri);
}
});
imageBitmap = BitmapFactory.decodeFile(mPath);
foto.setImageBitmap(imageBitmap);
break;
case SELECT_PICTURE:
Uri path2 = data.getData();
//Codigo para subir la imagen a Firebase
StorageReference filePath2 = mStorage.child("Fotos Aviso").child(path2.getLastPathSegment());
filePath2.putFile(path2).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(Fotos.this, "Se ha subido la foto a FireBase", Toast.LENGTH_SHORT).show();
}
});
foto.setImageURI(path2);
imageBitmap = drawableToBitmap(foto.getDrawable());
break;
}
}
}