Get data from Cloud Firestore











up vote
3
down vote

favorite












Picture



I need to get data from Firestore Firebase, I need to get the value of field "Company" from "employer" collection -> "TH17..." document. I try some things but it didnt work.



How I can do this?



I try this:



docref = db.collection("employer").document("TH17...");
docref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
}
}
}
});









share|improve this question
























  • Show what you have tried. So that the answer is much more focused on the issue you are facing
    – Pavan Varma
    yesterday












  • @PavanVarma I add what i tried
    – matan
    yesterday










  • small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
    – Pavan Varma
    yesterday















up vote
3
down vote

favorite












Picture



I need to get data from Firestore Firebase, I need to get the value of field "Company" from "employer" collection -> "TH17..." document. I try some things but it didnt work.



How I can do this?



I try this:



docref = db.collection("employer").document("TH17...");
docref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
}
}
}
});









share|improve this question
























  • Show what you have tried. So that the answer is much more focused on the issue you are facing
    – Pavan Varma
    yesterday












  • @PavanVarma I add what i tried
    – matan
    yesterday










  • small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
    – Pavan Varma
    yesterday













up vote
3
down vote

favorite









up vote
3
down vote

favorite











Picture



I need to get data from Firestore Firebase, I need to get the value of field "Company" from "employer" collection -> "TH17..." document. I try some things but it didnt work.



How I can do this?



I try this:



docref = db.collection("employer").document("TH17...");
docref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
}
}
}
});









share|improve this question















Picture



I need to get data from Firestore Firebase, I need to get the value of field "Company" from "employer" collection -> "TH17..." document. I try some things but it didnt work.



How I can do this?



I try this:



docref = db.collection("employer").document("TH17...");
docref.get().addOnCompleteListener(new OnCompleteListener<DocumentSnapshot>() {
@Override
public void onComplete(@NonNull Task<DocumentSnapshot> task) {
if (task.isSuccessful()) {
DocumentSnapshot document = task.getResult();
if (document.exists()) {
String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());
}
}
}
});






java android firebase google-cloud-firestore






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 16 hours ago









Alex Mamo

35.3k62354




35.3k62354










asked yesterday









matan

247




247












  • Show what you have tried. So that the answer is much more focused on the issue you are facing
    – Pavan Varma
    yesterday












  • @PavanVarma I add what i tried
    – matan
    yesterday










  • small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
    – Pavan Varma
    yesterday


















  • Show what you have tried. So that the answer is much more focused on the issue you are facing
    – Pavan Varma
    yesterday












  • @PavanVarma I add what i tried
    – matan
    yesterday










  • small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
    – Pavan Varma
    yesterday
















Show what you have tried. So that the answer is much more focused on the issue you are facing
– Pavan Varma
yesterday






Show what you have tried. So that the answer is much more focused on the issue you are facing
– Pavan Varma
yesterday














@PavanVarma I add what i tried
– matan
yesterday




@PavanVarma I add what i tried
– matan
yesterday












small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
– Pavan Varma
yesterday




small hunch did you add <uses-permission android:name="android.permission.INTERNET" /> in Manifest
– Pavan Varma
yesterday












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted











I need to get the value of field "company" from "employer" collection -> "TH17..." document.




To solve this, please change the following lines of code:



String p= document.getData().toString();
Log.d("TAG", "DocumentSnapshot data: " + document.getData());


to



String company = document.getString("Company");
Log.d("TAG", "Company: " + company);


The result in your logcat will be:



Company: Test





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














     

    draft saved


    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230921%2fget-data-from-cloud-firestore%23new-answer', 'question_page');
    }
    );

    Post as a guest
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    1
    down vote



    accepted











    I need to get the value of field "company" from "employer" collection -> "TH17..." document.




    To solve this, please change the following lines of code:



    String p= document.getData().toString();
    Log.d("TAG", "DocumentSnapshot data: " + document.getData());


    to



    String company = document.getString("Company");
    Log.d("TAG", "Company: " + company);


    The result in your logcat will be:



    Company: Test





    share|improve this answer



























      up vote
      1
      down vote



      accepted











      I need to get the value of field "company" from "employer" collection -> "TH17..." document.




      To solve this, please change the following lines of code:



      String p= document.getData().toString();
      Log.d("TAG", "DocumentSnapshot data: " + document.getData());


      to



      String company = document.getString("Company");
      Log.d("TAG", "Company: " + company);


      The result in your logcat will be:



      Company: Test





      share|improve this answer

























        up vote
        1
        down vote



        accepted







        up vote
        1
        down vote



        accepted







        I need to get the value of field "company" from "employer" collection -> "TH17..." document.




        To solve this, please change the following lines of code:



        String p= document.getData().toString();
        Log.d("TAG", "DocumentSnapshot data: " + document.getData());


        to



        String company = document.getString("Company");
        Log.d("TAG", "Company: " + company);


        The result in your logcat will be:



        Company: Test





        share|improve this answer















        I need to get the value of field "company" from "employer" collection -> "TH17..." document.




        To solve this, please change the following lines of code:



        String p= document.getData().toString();
        Log.d("TAG", "DocumentSnapshot data: " + document.getData());


        to



        String company = document.getString("Company");
        Log.d("TAG", "Company: " + company);


        The result in your logcat will be:



        Company: Test






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 16 hours ago

























        answered 16 hours ago









        Alex Mamo

        35.3k62354




        35.3k62354






























             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53230921%2fget-data-from-cloud-firestore%23new-answer', 'question_page');
            }
            );

            Post as a guest




















































































            Popular posts from this blog

            List item for chat from Array inside array React Native

            Thiostrepton

            Caerphilly