C
C
Comatu2017-09-11 20:21:06
Android
Comatu, 2017-09-11 20:21:06

How to get url from firebase database?

There is such a Firebase database:
569cc209d5e6437982b95b62662db771.png
Authorization removed, full access to data. Wrote like this and got stuck...

public void onClick(View view) {

            // [START initialize_database_ref]
            mDatabase = FirebaseDatabase.getInstance().getReference();
            // [END initialize_database_ref]
        ValueEventListener bookListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
            }

            @Override
            public void onCancelled(DatabaseError databaseError) {


            }
        };

        // Загружаем картинку
        Picasso.with(this)
                .load(coverUrl)
        .into(mImageView);

How to get the url from any database entry and write it to a variable? Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
C
Comatu, 2017-09-12
@Comatu

Helped on another resource, I publish the answer:

public void onClick(View view) {

            // [START initialize_database_ref]
            ref = FirebaseDatabase.getInstance().getReference().child("books").child("book_1");
            // [END initialize_database_ref]
        ValueEventListener bookListener = new ValueEventListener() {
            @Override
            public void onDataChange(DataSnapshot dataSnapshot) {
                String url = dataSnapshot.child("coverUrl").getValue(String.class);
                // Загружаем картинку
                Picasso.with(MainActivity.this)
                        .load(url)
                        .into(mImageView);

            }

            @Override
            public void onCancelled(DatabaseError databaseError) {


            }
        };
        //вешаем наш слушатель на нашу ссылку
        ref.addValueEventListener(bookListener);

    }

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question