How to know how many people are connected to Firebase in Android studio?










1















pretty straightforward question. im making an android app that uses firebase authentication for users to connect with email and password an also the firebase realtime database service.



i wanted to know if i can check through android studio how many people are currently connected to my database(through Firebase Authentication)



thanks in advance!










share|improve this question
























  • There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

    – Frank van Puffelen
    Apr 11 '17 at 12:55















1















pretty straightforward question. im making an android app that uses firebase authentication for users to connect with email and password an also the firebase realtime database service.



i wanted to know if i can check through android studio how many people are currently connected to my database(through Firebase Authentication)



thanks in advance!










share|improve this question
























  • There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

    – Frank van Puffelen
    Apr 11 '17 at 12:55













1












1








1








pretty straightforward question. im making an android app that uses firebase authentication for users to connect with email and password an also the firebase realtime database service.



i wanted to know if i can check through android studio how many people are currently connected to my database(through Firebase Authentication)



thanks in advance!










share|improve this question
















pretty straightforward question. im making an android app that uses firebase authentication for users to connect with email and password an also the firebase realtime database service.



i wanted to know if i can check through android studio how many people are currently connected to my database(through Firebase Authentication)



thanks in advance!







android firebase firebase-realtime-database firebase-authentication






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Apr 11 '17 at 12:55









Frank van Puffelen

233k29380406




233k29380406










asked Apr 11 '17 at 12:14









oren Agmonoren Agmon

82




82












  • There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

    – Frank van Puffelen
    Apr 11 '17 at 12:55

















  • There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

    – Frank van Puffelen
    Apr 11 '17 at 12:55
















There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

– Frank van Puffelen
Apr 11 '17 at 12:55





There is a sample present system in the Firebase documentation: firebase.google.com/docs/database/android/…

– Frank van Puffelen
Apr 11 '17 at 12:55












2 Answers
2






active

oldest

votes


















0














It's very simple. Every time a user is connecting to your app, add him in a Firebase category, named users. Than you can query on that category to see the exact number of users like this: int numberOfUsers = dataSnapshot.getChildrenCount();. Hope it helps.






share|improve this answer























  • i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

    – oren Agmon
    Apr 11 '17 at 12:31











  • There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

    – Alex Mamo
    Apr 11 '17 at 12:38


















0














var database = firebase.database();

// connecting users
var connectionsRef = database.ref("/connections");

var connectedRef = database.ref(".info/connected");
// Number of online users is the number of objects in the presence list.

// When the client's connection state changes...
connectedRef.on("value", function(snap)

// If they are connected..
if (snap.val())

// Add user to the connections list.
var con = connectionsRef.push(true);

// Remove user from the connection list when they disconnect.
con.onDisconnect().remove();

);

// When first loaded or when the connections list changes...
connectionsRef.on("value", function(snapshot) {

// Display the viewer count in the html.
// The number of online users is the number of children in the connections list.
console.log("numers of players are:"+ snapshot.numChildren());
$(".displayDiv").text(snapshot.numChildren());





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',
    autoActivateHeartbeat: false,
    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%2f43345624%2fhow-to-know-how-many-people-are-connected-to-firebase-in-android-studio%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    It's very simple. Every time a user is connecting to your app, add him in a Firebase category, named users. Than you can query on that category to see the exact number of users like this: int numberOfUsers = dataSnapshot.getChildrenCount();. Hope it helps.






    share|improve this answer























    • i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

      – oren Agmon
      Apr 11 '17 at 12:31











    • There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

      – Alex Mamo
      Apr 11 '17 at 12:38















    0














    It's very simple. Every time a user is connecting to your app, add him in a Firebase category, named users. Than you can query on that category to see the exact number of users like this: int numberOfUsers = dataSnapshot.getChildrenCount();. Hope it helps.






    share|improve this answer























    • i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

      – oren Agmon
      Apr 11 '17 at 12:31











    • There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

      – Alex Mamo
      Apr 11 '17 at 12:38













    0












    0








    0







    It's very simple. Every time a user is connecting to your app, add him in a Firebase category, named users. Than you can query on that category to see the exact number of users like this: int numberOfUsers = dataSnapshot.getChildrenCount();. Hope it helps.






    share|improve this answer













    It's very simple. Every time a user is connecting to your app, add him in a Firebase category, named users. Than you can query on that category to see the exact number of users like this: int numberOfUsers = dataSnapshot.getChildrenCount();. Hope it helps.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 11 '17 at 12:16









    Alex MamoAlex Mamo

    41.8k72859




    41.8k72859












    • i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

      – oren Agmon
      Apr 11 '17 at 12:31











    • There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

      – Alex Mamo
      Apr 11 '17 at 12:38

















    • i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

      – oren Agmon
      Apr 11 '17 at 12:31











    • There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

      – Alex Mamo
      Apr 11 '17 at 12:38
















    i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

    – oren Agmon
    Apr 11 '17 at 12:31





    i basically want to know how many people are playing the game right now, and all of the players who play are connected to firebase. so how do i know when to remove them?( i only need to remove them if the entire app is closed and they stopped playing)..

    – oren Agmon
    Apr 11 '17 at 12:31













    There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

    – Alex Mamo
    Apr 11 '17 at 12:38





    There 2 different things. One is, how many players are connected to Firebase and second how many players are connected to Firebase and are playing at the same time. So, in order to answer the second question, because for the first you have the answer above, you need to create another filed in your database named onlineStatus in which you'll got to put true if the player is online and false if it's not. You'll need also to put on that field a ValueEventListener to see in real time which is the status of the playes and to take action accordingly .

    – Alex Mamo
    Apr 11 '17 at 12:38













    0














    var database = firebase.database();

    // connecting users
    var connectionsRef = database.ref("/connections");

    var connectedRef = database.ref(".info/connected");
    // Number of online users is the number of objects in the presence list.

    // When the client's connection state changes...
    connectedRef.on("value", function(snap)

    // If they are connected..
    if (snap.val())

    // Add user to the connections list.
    var con = connectionsRef.push(true);

    // Remove user from the connection list when they disconnect.
    con.onDisconnect().remove();

    );

    // When first loaded or when the connections list changes...
    connectionsRef.on("value", function(snapshot) {

    // Display the viewer count in the html.
    // The number of online users is the number of children in the connections list.
    console.log("numers of players are:"+ snapshot.numChildren());
    $(".displayDiv").text(snapshot.numChildren());





    share|improve this answer





























      0














      var database = firebase.database();

      // connecting users
      var connectionsRef = database.ref("/connections");

      var connectedRef = database.ref(".info/connected");
      // Number of online users is the number of objects in the presence list.

      // When the client's connection state changes...
      connectedRef.on("value", function(snap)

      // If they are connected..
      if (snap.val())

      // Add user to the connections list.
      var con = connectionsRef.push(true);

      // Remove user from the connection list when they disconnect.
      con.onDisconnect().remove();

      );

      // When first loaded or when the connections list changes...
      connectionsRef.on("value", function(snapshot) {

      // Display the viewer count in the html.
      // The number of online users is the number of children in the connections list.
      console.log("numers of players are:"+ snapshot.numChildren());
      $(".displayDiv").text(snapshot.numChildren());





      share|improve this answer



























        0












        0








        0







        var database = firebase.database();

        // connecting users
        var connectionsRef = database.ref("/connections");

        var connectedRef = database.ref(".info/connected");
        // Number of online users is the number of objects in the presence list.

        // When the client's connection state changes...
        connectedRef.on("value", function(snap)

        // If they are connected..
        if (snap.val())

        // Add user to the connections list.
        var con = connectionsRef.push(true);

        // Remove user from the connection list when they disconnect.
        con.onDisconnect().remove();

        );

        // When first loaded or when the connections list changes...
        connectionsRef.on("value", function(snapshot) {

        // Display the viewer count in the html.
        // The number of online users is the number of children in the connections list.
        console.log("numers of players are:"+ snapshot.numChildren());
        $(".displayDiv").text(snapshot.numChildren());





        share|improve this answer















        var database = firebase.database();

        // connecting users
        var connectionsRef = database.ref("/connections");

        var connectedRef = database.ref(".info/connected");
        // Number of online users is the number of objects in the presence list.

        // When the client's connection state changes...
        connectedRef.on("value", function(snap)

        // If they are connected..
        if (snap.val())

        // Add user to the connections list.
        var con = connectionsRef.push(true);

        // Remove user from the connection list when they disconnect.
        con.onDisconnect().remove();

        );

        // When first loaded or when the connections list changes...
        connectionsRef.on("value", function(snapshot) {

        // Display the viewer count in the html.
        // The number of online users is the number of children in the connections list.
        console.log("numers of players are:"+ snapshot.numChildren());
        $(".displayDiv").text(snapshot.numChildren());






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 21:58









        Stephen M

        514419




        514419










        answered Nov 13 '18 at 18:12









        GurneetGurneet

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43345624%2fhow-to-know-how-many-people-are-connected-to-firebase-in-android-studio%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            這個網誌中的熱門文章

            How to read a connectionString WITH PROVIDER in .NET Core?

            In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

            Museum of Modern and Contemporary Art of Trento and Rovereto