我正在尝试在ProfileActivity中加载用户个人资料图片,但未加载。图片会加载到FirebaseDatabase中,但不会加载到ProfileActivity中。
这是我的ProfileActivity.java
private StorageReference storageReference;
//path where images of user profile and cover will be stored
private String storagePath = "Users_Profile_Cover_Images/";
//permission constants
private static final int CAMERA_REQUEST_CODE = 100;
private static final int STORAGE_REQUEST_CODE = 200;
private static final int IMAGE_PICK_CAMERA_CODE = 400;
//arrays of permissions to be requested
private String[] cameraPermission;
private String[] storageaPermission;
//uri of picked images
private Uri image_uri;
//for checking profile or cover photo
private String profileOrCoverPhoto;
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
// Inflate the layout for this fragment
View view = inflater.inflate(R.layout.activity_profile, container,
false);
//init arrays of permissions
cameraPermission = new String[]{Manifest.permission.CAMERA, Manifest.permission.WRITE_EXTERNAL_STORAGE};
storageaPermission = new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE};
//init views
avatarIv = view.findViewById(R.id.profileIv);
Query query = databaseReference.orderByChild("email").equalTo(user.getEmail());
query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
//get data
String email = "" + ds.child("email").getValue();
String image = "" + ds.child("image").getValue();
try {
Picasso.get().load(image).fit().into(avatarIv);
}
catch (Exception e)
{
Picasso.get().load(R.drawable.ic_people).into(avatarIv);
}
请有人帮助我或向我解释问题所在。我尝试了Glide和Picasso,但都没有用。