0
I’m starting programming for android and I have a project in android studio that creates registration with photo, I added firebase and not how to create the code to send this data with photo, name... If anyone could give me an example of how to do that, I’d appreciate it. follows the method I used to upload the image (photo).
mImageView.setOnClickListener( new View.OnClickListener() {
@RequiresApi(api = Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onClick(View v) {
ActivityCompat.requestPermissions( Produtos.this, new String[]{
Manifest.permission.READ_EXTERNAL_STORAGE}, REQUEST_CODE_GALLERY );
}
} );
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == REQUEST_CODE_GALLERY) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
Intent galleryIntent = new Intent( Intent.ACTION_GET_CONTENT );
galleryIntent.setType( "image/*" );
startActivityForResult( galleryIntent, REQUEST_CODE_GALLERY );
} else {
Toast.makeText( this, "Você não tem permissão", Toast.LENGTH_SHORT ).show();
}
return;
}
super.onRequestPermissionsResult( requestCode, permissions, grantResults );
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_GALLERY && resultCode == RESULT_OK) {
Uri imageUri = data.getData();
CropImage.activity( imageUri )
.setGuidelines( CropImageView.Guidelines.ON )
.setAspectRatio( 1, 1 )
.start( this );
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult( data );
if (resultCode == RESULT_OK) {
Uri resultUri = result.getUri();
mImageView.setImageURI( resultUri );
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
super.onActivityResult( requestCode, resultCode, data );
}
How to send this image to Firebase Storage?