Firebase连接检查Android中的在线离线状态 [英] firebase connection check online offline status in android

查看:97
本文介绍了Firebase连接检查Android中的在线离线状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户同时关闭wi-fi,3g,4g等,然后反向(没有互联网连接). Firebase数据库名称子连接:(是/否) 因此,当wi-fi,3g,4g等互联网连接关闭或丢失时,该用户处于离线状态,因此找不到他.

If user turn off both wi-fi, 3g, 4g, and so on and reverse (no internet connection). Firebase database name child connections:(true/false) So, when internet connections, wi-fi, 3g, 4g, and so on are off or missing, the user is offline so he can't be found.

请记住以下两种情况:之前和之后.如果用户在其他用户搜索他之前先处于离线状态,则该用户将不会显示在列表结果中;如果该用户在其他用户搜索他之后已离线,则该用户将不再显示该图标.

Remember the two scenarios: Before and After. If user is offline before an other user search him, then he will not displayed in the list result, if user is off-line after an other user search him, then it will display NO MORE AVAILABLE icon on the user

请帮助我解决这个问题. 提前致谢.

Kindly some one help me for this problem.. Thanks in advanced.

推荐答案

尽管已经过去了一年多,但还是要消除混乱.亚历克斯(Alex)的问题想实现一个实时聊天场景,其中每个用户都可以在终端或设备上查看每个人的在线状态. 一个简单的解决方案是创建一个节点,所有用户将在其中注入各自的在线状态.例如

Though this is more than a year late, to clear up the confusion. Alex's question would like to implement a live chat scenario in which each user can view everyone's online status at their ends or on their devices. A simple solution be to create a node where all users would inject their online status each. e.g.

    //say your realtime database has the child `online_statuses`
    DatabaseReference online_status_all_users = FirebaseDatabase.getInstance().getReference().child("online_statuses");

    //on each user's device when connected they should indicate e.g. `linker` should tell everyone he's snooping around
    online_status_all_users.child("@linker").setValue("online");
    //also when he's not doing any snooping or if snooping goes bad he should also tell
    online_status_all_users.child("@linker").onDisconnect().setValue("offline")

因此,如果说 mario 的另一个用户从他的末端开始检查 linker ,他可以确保如果 在线,即

So if another user, say mario checks for linker from his end he can be sure some snooping around is still ongoing if linker is online i.e.

    DatabaseReference online_status_all_users = FirebaseDatabase.getInstance().getReference().child("online_statuses");
    online_status_all_users.child("@linker").addValueEventListener(new ValueEventListener() {
      @Override
      public void onDataChange(DataSnapshot dataSnapshot) {
        String snooping_status = dataSnapshot.getValue(String.class);
        //mario should decide what to do with linker's snooping status here e.g.
         if(snooping_status.contentEquals("online")){
            //tell linker to stop doing sh*t
         }else{
            //tell linker to do a lot of sh****t
         }     
      }

      @Override
      public void onCancelled(DatabaseError databaseError) {

      }
    });

这篇关于Firebase连接检查Android中的在线离线状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆