'My ImageView disappears when I try to set the image from my Firebase storage
I want to set a picture from my storage by Picasso, however it doesnt work. Initially, there is an icon in my ImageView, but it doesnt show as well after I get to the Activity.
here's code
public class ProfileFragment extends Fragment {
TextView fullNameText, emailText, dateBirthText, phoneText;
TextView addressText;
FloatingActionButton profileEditBtn;
TextView uploadImgBtn;
ImageView profileImg;
String phone, link;
private DatabaseReference dbRef = FirebaseDatabase.getInstance().getReference().child("image");
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
Bundle bundle = this.getArguments();
phone = bundle.getString("phone");
View myView = inflater.inflate(R.layout.fragment_profile, container, false);
fullNameText = myView.findViewById(R.id.full_name_text);
emailText = myView.findViewById(R.id.email_text);
dateBirthText = myView.findViewById(R.id.date_birth_text);
addressText = myView.findViewById(R.id.address_text);
phoneText = myView.findViewById(R.id.phone_text);
profileImg = myView.findViewById(R.id.profile_img);
uploadImgBtn = myView.findViewById(R.id.upload_img_btn);
uploadImgBtn.setOnClickListener(view -> {
Intent intent = new Intent(getContext(), UploadProfileImage.class);
intent.putExtra("phone", phone);
startActivity(intent);
});
return myView;
}
@Override
public void onStart() {
super.onStart();
dbRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
link = dataSnapshot.getValue(String.class);
// this is the link to the image in firebase
System.out.println(link);
Picasso.get()
.load(link)
.fit()
.centerCrop()
.into(profileImg);
profileImg.setVisibility(View.VISIBLE);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
});
}
}
my xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/profile_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="My personal data"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.434" />
<TextView
android:id="@+id/full_name_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Full Name: "
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_title"
app:layout_constraintVertical_bias="0.053" />
<TextView
android:id="@+id/email_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Email: "
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_title"
app:layout_constraintVertical_bias="0.175" />
<TextView
android:id="@+id/date_birth_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Date of birth: "
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_title"
app:layout_constraintVertical_bias="0.416" />
<TextView
android:id="@+id/address_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Address: "
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_title"
app:layout_constraintVertical_bias="0.527" />
<TextView
android:id="@+id/phone_text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:text="Phone: "
android:textSize="18sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/profile_title"
app:layout_constraintVertical_bias="0.293" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/profile_edit_btn"
android:layout_width="64dp"
android:layout_height="64dp"
android:clickable="true"
android:contentDescription="Edit profile"
app:fabCustomSize="64dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.953"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/address_text"
app:layout_constraintVertical_bias="0.198"
app:srcCompat="@drawable/ic_edit" />
<TextView
android:id="@+id/upload_img_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Upload profile image"
android:textColor="#03A9F4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/profile_edit_btn"
app:layout_constraintHorizontal_bias="0.079"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/address_text"
app:layout_constraintVertical_bias="0.288" />
<ImageView
android:id="@+id/profile_img"
android:layout_width="230dp"
android:layout_height="230dp"
app:layout_constraintBottom_toTopOf="@+id/profile_title"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.702"
tools:ignore="ImageContrastCheck"
android:src="@drawable/ic_android"/>
</androidx.constraintlayout.widget.ConstraintLayout>
I ve tried to use Glide instead of picasso, but it didnt work anyways. I'm also pretty sure that my link to file is correct.
realtime db
{
"Users" : {
"123456789" : {
"address" : "",
"date" : "2022-03-27",
"email" : "[email protected]",
"fullName" : "me",
"password" : "qwerty12345",
"phone" : "123456789"
}
},
"image" : "gs://myproj-8984f.appspot.com/images/gachiava.png"
}
Solution 1:[1]
Please check whether the Picasso can load with another url by manally adding a url.
Picasso.get().load("your link here").fit().centerCrop().into(profileImg);
And make sure you have added the correct internet permission to Android manifest.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | z1nc0r3 |
