Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hellofaizan/a78ac0f91c3698be5d1739ce01d29e63 to your computer and use it in GitHub Desktop.
Save hellofaizan/a78ac0f91c3698be5d1739ce01d29e63 to your computer and use it in GitHub Desktop.
Load Image From Firebase Real Time Database
// Load NavBar Image From Firebase
DatabaseReference getImage = databaseReferenceImage.child("NavBarImage");
getImage.addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
// getting a DataSnapshot for the location at the specified
// relative path and getting in the link variable
String link = dataSnapshot.getValue(String.class);
// loading that data into rImage
// variable which is ImageView
Glide.with(MainActivity.this).load(link).into(eventImage);
eventImage.setOnClickListener(v -> {
if (!NavBarLink.isEmpty()){
Intent pAD1 = new Intent(Intent.ACTION_VIEW, Uri.parse(NavBarLink));
startActivity(pAD1);
}
});
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
// we are showing that error message in toast
Toast.makeText(MainActivity.this, "Error Loading Image: " + databaseError.getMessage(), Toast.LENGTH_SHORT).show();
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment