Recommand · June 2, 2021 0

Retrieving Base64 encoded Image from Firebase and show it on Android App

I’m trying to retrieve a Base64 encoded image from Firebase and show it on an App developed in Android Studio. The code is putting something on the ImageView element, but I think that is just a white image, because the background of the ImageView element just disappears. Can someone help?

public class MainActivity extends AppCompatActivity {

    private Button setting;

    protected void onCreate(Bundle savedInstanceState) {
        ImageView image = (ImageView) findViewById(;
        FirebaseDatabase.getInstance().getReference().child("photos").child("realtime").child("-MbB__vRH7wrFXqL_8UO").child("photo").addValueEventListener(new ValueEventListener() {
            public void onDataChange(DataSnapshot dataSnapshot) {
                String imagestr = dataSnapshot.getValue(String.class);
                String imageclean = imagestr.replace("data:image/jpeg;base64,", "");
                //64Base to BitMap Conversion
                byte[] decodedString = Base64.decode(imageclean, Base64.DEFAULT);
                Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString, 0, decodedString.length);
                //Toast.makeText(MainActivity.this, imageclean, Toast.LENGTH_SHORT).show();
            public void onCancelled(DatabaseError error) {
                // Failed to read value
                Log.w(TAG, "Failed to read value.", error.toException());