我正在尝试从Firebase获取下载URL,但这给了我另一个链接,例如“ com.google.android.gms.tasks.zzu@1bd1fe4”,而不是上传的图像链接。
这是我的代码:
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult( requestCode, resultCode, data );
if (requestCode == GalleryRequest && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri imagePath = data.getData();
CropImage.activity( imagePath )
.setGuidelines( CropImageView.Guidelines.ON )
.setAspectRatio( 1, 1 )
.start( profileUpdate.this );
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult( data );
if (resultCode == RESULT_OK) {
imageUri = result.getUri();
Log.d( TAG, "onActivityResult: Image Uri " + imageUri.toString() );
final ProgressDialog progressDialog = new ProgressDialog(this);
progressDialog.setTitle("Uploading...");
progressDialog.show();
mProfile_image.setImageURI( imageUri );
StorageReference imagePath = mStorage.child(getString( R.string.all_drivers)).child(user_id).child("profile.jpg");
imagePath.putFile(imageUri).addOnSuccessListener( new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
progressDialog.dismiss();
String image_firebase_uri = taskSnapshot.getMetadata().getReference().getDownloadUrl().toString();
mReference.child(getString(R.string.all_drivers)).child(user_id).child("userDp").setValue(image_firebase_uri);
}
} ).addOnFailureListener( new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
progressDialog.dismiss();
Toast.makeText( profileUpdate.this, "Failed"+e.getMessage(), Toast.LENGTH_SHORT ).show();
}
} ).addOnProgressListener( new OnProgressListener<UploadTask.TaskSnapshot>() {
@Override
public void onProgress(UploadTask.TaskSnapshot taskSnapshot) {
double progress = (100.0*taskSnapshot.getBytesTransferred()/taskSnapshot.getTotalByteCount());
progressDialog.setMessage( "Profile Updated "+(int)progress+"%");
}
} );
} else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
Exception error = result.getError();
}
}
}
我正在尝试获取上传图像的实际路径。