使用毕加索库无法从firebase检索图像

时间:2019-11-13 02:01:48

标签: android firebase picasso

我正在使用Picasso库制作聊天应用程序

  

https://square.github.io/picasso/   我正在使用circleImageView实现'de.hdodenhof:circleimageview:3.0.1'

这是我正在使用的图像裁剪器

implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'

在用户个人资料图像中,我能够成功在Firebae中上传图像,但是当我从Firebase检索图像时,图像消失了。

这些是我的依赖项

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.google.android.material:material:1.2.0-alpha01'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    implementation 'com.google.firebase:firebase-auth:16.0.5'
    implementation 'com.google.firebase:firebase-database:16.0.4'
    implementation 'com.google.firebase:firebase-storage:16.0.4'
    implementation 'androidx.legacy:legacy-support-v4:1.0.0'
    implementation 'de.hdodenhof:circleimageview:3.0.1'
    implementation 'com.theartofdev.edmodo:android-image-cropper:2.8.+'
    implementation 'com.squareup.picasso:picasso:2.71828'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

这是我的代码,用于将图像保存在Firebase中并使用Image Cropper

@Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if(requestCode == GalleryPick && resultCode == RESULT_OK && data != null)
        {
            Uri imageUri = data.getData();

            CropImage.activity()
                    .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)
            {
                loadingBar.setTitle("Set profile image");
                loadingBar.setMessage("Please wait, your image is uploading....");
                loadingBar.setCanceledOnTouchOutside(false);
                loadingBar.show();

                Uri resultUri = result.getUri();
                StorageReference filePath = userProfileImageRef.child(currentUserId + ".jpg");
                filePath.putFile(resultUri).addOnCompleteListener(new OnCompleteListener<UploadTask.TaskSnapshot>() {
                    @Override
                    public void onComplete(@NonNull Task<UploadTask.TaskSnapshot> task)
                    {
                     if (task.isSuccessful())
                     {
                         Toast.makeText(SettingsActivity.this, "Image Uploaded Successfully", Toast.LENGTH_SHORT).show();
                         final String downloadUrl = task.getResult().getMetadata().getReference().getDownloadUrl().toString();

                         RootRef .child("Users").child(currentUserId).child("image")
                                 .setValue(downloadUrl)
                                 .addOnCompleteListener(new OnCompleteListener<Void>() {
                                     @Override
                                     public void onComplete(@NonNull Task<Void> task)
                                     {
                                      if (task.isSuccessful())
                                      {
                                          Toast.makeText(SettingsActivity.this, "Image saved", Toast.LENGTH_SHORT).show();
                                          loadingBar.dismiss();
                                      }
                                      else
                                      {
                                          String message = task.getException().toString();
                                          Toast.makeText(SettingsActivity.this, "Error: "+ message, Toast.LENGTH_SHORT).show();
                                          loadingBar.dismiss();
                                      }
                                     }
                                 });
                     }
                     else
                     {
                         String message = task.getException().toString();
                         Toast.makeText(SettingsActivity.this, "Error: " + message, Toast.LENGTH_SHORT).show();
                         loadingBar.dismiss();
                     }
                    }
                });
            }
        }

    }

在这里,我正在从Firebase检索图像。但是图像和CircleImageView都消失了。一切都很好。

private void RetrieveUserInfo()
    {
        RootRef.child("Users").child(currentUserId)
                .addValueEventListener(new ValueEventListener() {
                    @Override
                    public void onDataChange(@NonNull DataSnapshot dataSnapshot)
                    {
                     if((dataSnapshot.exists()) && (dataSnapshot.hasChild("name") && (dataSnapshot.hasChild("image"))))
                     {
                         String retrieveUserName = dataSnapshot.child("name").getValue().toString();
                         String retrieveStatus = dataSnapshot.child("Status").getValue().toString();
                         String retrieveProfileImage = dataSnapshot.child("image").getValue().toString();

                         userName.setText(retrieveUserName);
                         userStatus.setText(retrieveStatus);
                         Picasso.get().load(retrieveProfileImage).into(userProfileImage);
                     }
                     else if ((dataSnapshot.exists()) && (dataSnapshot.hasChild("name")))
                     {
                         String retrieveUserName = dataSnapshot.child("name").getValue().toString();
                         String retrieveStatus = dataSnapshot.child("Status").getValue().toString();

                         userName.setText(retrieveUserName);
                         userStatus.setText(retrieveStatus);
                     }
                     else
                        {
                            userName.setVisibility(View.VISIBLE);
                            Toast.makeText(SettingsActivity.this, "Please update profile info", Toast.LENGTH_SHORT).show();
                        }
                    }

                    @Override
                    public void onCancelled(@NonNull DatabaseError databaseError)
                    {

                    }
                });
    }

图像裁剪器工作正常,当我上传图像时,它也出现在firebase中,但是在应用程序中消失了,我也尝试了不使用图像裁剪器,但是它不起作用。

0 个答案:

没有答案