我一直在尝试使用我的应用程序将图像上传到Firebase存储,但没有成功。我已经正确添加了所有依赖项,但是当我尝试单击图像时,未选择任何图像,并且将我带回了该应用程序。这是代码。
profilePicture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, GALLERY_PICK);
}
});
return RootView;
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == GALLERY_PICK && resultCode == RESULT_OK && data != null) {
Uri imageUri = data.getData();
CropImage.activity()
.setGuidelines(CropImageView.Guidelines.ON)
.setAspectRatio(1, 1)
.start(getContext(), this);
}
if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
CropImage.ActivityResult result = CropImage.getActivityResult(data);
if (requestCode == RESULT_OK){
Uri resultUri = result.getUri();
StorageReference filePath = userProfileImagesRef.child(onlineUserID + ".jpg");
filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
@Override
public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task) {
if (task.isSuccessful()){
Toast.makeText(getContext(), "Your photo has been uploaded successfully", Toast.LENGTH_LONG).show();
}else {
String error = task.getException().toString();
Toast.makeText(getContext(), "Photo could not be uploaded "+ error, Toast.LENGTH_SHORT).show();
}
}
});
}
}
}
任何帮助将不胜感激。 谢谢。