HOW TO RETRIVED IMAGE FROM FIREBASE IN ANDROID

 HOW TO RETRIVED IMAGE FROM FIREBASE IN   ANDROID



  • add Dependences in build.gradle file
  • dependencies {
       
    // Import the BoM for the Firebase platform
        implementation platform
    ('com.google.firebase:firebase-bom:28.4.0')


       
    // Declare the dependency for the Cloud Storage library
       
    // When using the BoM, you don't specify versions in Firebase library dependencies
       
    implementation 'com.google.firebase:firebase-storage-latest version'//include latest version
  • Add Imageview in xml to retrived image
  • <ImageView
    android:id="@+id/image"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent"
    app:layout_constraintVertical_bias="0.966"
    android:contentDescription="TODO" />
  •  Now come to Backend part (JAVA)
  • Create a reference to upload, download, or delete a file, or to get or update its metadata.
  • private StorageReference mStorageReference;
  • Next, you can create a reference to a location lower in the tree, say "images/space.jpg" by using the child() method on an existing reference.
  • mStorageReference = FirebaseStorage.getInstance().getReference().child("picture/pandey.png");
    try {
    final File localFile = File.createTempFile("pandey", "png");
    mStorageReference.getFile(localFile)
    .addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
    @Override
    public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
    Toast.makeText(MainActivity.this,"Picture Retrieved",Toast.LENGTH_SHORT).show();
    Bitmap bitmap = BitmapFactory.decodeFile(localFile.getAbsolutePath());
    ((ImageView)findViewById(R.id.image)).setImageBitmap(bitmap);
    }
    }).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception e) {

    Toast.makeText(MainActivity.this,"Error ",Toast.LENGTH_SHORT).show();
    }
    });
    } catch (IOException e) {
    e.printStackTrace();
    }




Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

CREATE UNIT CONVERTER APP

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees