How to know how many people are connected to Firebase in Android studio?
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
add a comment |
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
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
add a comment |
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
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
android firebase firebase-realtime-database firebase-authentication
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
add a comment |
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
add a comment |
2 Answers
2
active
oldest
votes
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.
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 namedonlineStatus
in which you'll got to puttrue
if the player isonline
andfalse
if it's not. You'll need also to put on that field aValueEventListener
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
add a comment |
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());
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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 namedonlineStatus
in which you'll got to puttrue
if the player isonline
andfalse
if it's not. You'll need also to put on that field aValueEventListener
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
add a comment |
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.
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 namedonlineStatus
in which you'll got to puttrue
if the player isonline
andfalse
if it's not. You'll need also to put on that field aValueEventListener
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
add a comment |
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.
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.
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 namedonlineStatus
in which you'll got to puttrue
if the player isonline
andfalse
if it's not. You'll need also to put on that field aValueEventListener
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
add a comment |
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 namedonlineStatus
in which you'll got to puttrue
if the player isonline
andfalse
if it's not. You'll need also to put on that field aValueEventListener
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
add a comment |
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());
add a comment |
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());
add a comment |
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());
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());
edited Nov 13 '18 at 21:58
Stephen M
514419
514419
answered Nov 13 '18 at 18:12
GurneetGurneet
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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