当我试图在 Firebase 存储中获取我的图像的下载 URL 时,我得到了一些奇怪的结果,我得到了这个结果
com.google.android.gms.tasks.zzu@3a6d712
这是我的代码
public class MainActivity extends AppCompatActivity {
private StorageReference mStorage;
private ProgressDialog mProgressDialog;
private static final int GALLERY_REQUEST_CODE = 1;
private static final int CAMERA_REQUEST_CODE = 2;
private Button uploadButton;
private Button captureButton;
ImageView imageViewBig, imageViewSmall;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStorage = FirebaseStorage.getInstance().getReference();
mProgressDialog = new ProgressDialog(this);
imageViewBig = findViewById(R.id.imageViewBig);
imageViewSmall = findViewById(R.id.imageViewSmall);
captureButton = findViewById(R.id.captureButton);
uploadButton = findViewById(R.id.uploadButton);
captureButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(Intent.ACTION_PICK);
intent.setType("image/*");
startActivityForResult(intent, GALLERY_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_REQUEST_CODE && resultCode == RESULT_OK) {
Uri uri = data.getData();
StorageReference filePath = mStorage.child("photos").child(uri.getLastPathSegment());
filePath.putFile(uri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(final UploadTask.TaskSnapshot taskSnapshot) {
Toast.makeText(MainActivity.this, "DONE", Toast.LENGTH_SHORT).show();
imageViewBig.setBackgroundColor(Color.GREEN);
imageViewBig.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Log.i("URL", taskSnapshot.getMetadata().getReference().getDownloadUrl().toString());
}
});
}
});
}
}
}
那么如何使用 picasso 获取正确的下载 URL 以将图像下载到图像视图中