How to get All Registered users, not only my contact lists on Firebase in my code





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







-1















I have this FetchMyUsersService Class, This class gets only users on my contact list, how i can get all Firebase users ? Please Help.



This is my Code



This is Dont written by me.



I Have more classes, but i think this my solution in this class, If not just tell me i share another classes on this project



public class FetchMyUsersService extends IntentService {
private static String EXTRA_PARAM1 = "my_id";
private static String EXTRA_PARAM2 = "token";
private HashMap<String, Contact> myContacts;
private ArrayList<User> myUsers;
private String myId, idToken;

public static boolean STARTED = false;

public FetchMyUsersService() {
super("FetchMyUsersService");
}

public static void startMyUsersService(Context context, String myId, String idToken) {
Intent intent = new Intent(context, FetchMyUsersService.class);
intent.putExtra(EXTRA_PARAM1, myId);
intent.putExtra(EXTRA_PARAM2, idToken);
context.startService(intent);
}


@Override
protected void onHandleIntent(Intent intent) {
STARTED = true;
myId = intent.getStringExtra(EXTRA_PARAM1);
idToken = intent.getStringExtra(EXTRA_PARAM2);
fetchMyContacts();
broadcastMyContacts();
fetchMyUsers();
broadcastMyUsers();
STARTED = false;
}

private void broadcastMyUsers() {
if (this.myUsers != null) {
Intent intent = new Intent(Helper.BROADCAST_MY_USERS);
intent.putParcelableArrayListExtra("data", this.myUsers);
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.sendBroadcast(intent);
}
}

private void fetchMyUsers() {
myUsers = new ArrayList<>();
try {
StringBuilder response = new StringBuilder();
URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
URLConnection conn = url.openConnection();
BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String line;
while ((line = rd.readLine()) != null) {
response.append(line).append(" ");
}
rd.close();

JSONObject responseObject = new JSONObject(response.toString());
Gson gson = new GsonBuilder().create();
Iterator<String> keys = responseObject.keys();
while (keys.hasNext()) {
String key = keys.next();
JSONObject innerJObject = responseObject.getJSONObject(key);
User user = gson.fromJson(innerJObject.toString(), User.class);
if (User.validate(user) && !user.getId().equals(myId)) {
String idTrim = Helper.getEndTrim(user.getId());
if (myContacts.containsKey(idTrim)) {
user.setNameInPhone(myContacts.get(idTrim).getName());
myUsers.add(user);
}
}
if (myUsers.size() == myContacts.size()) {
break;
}
}

Collections.sort(myUsers, new Comparator<User>() {
@Override
public int compare(User user1, User user2) {
return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
}
});
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
}

private void broadcastMyContacts() {
if (this.myContacts != null) {
new Helper(this).setMyUsersNameCache(myContacts);
Intent intent = new Intent(Helper.BROADCAST_MY_CONTACTS);
intent.putExtra("data", this.myContacts);
LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
localBroadcastManager.sendBroadcast(intent);
}
}

private void fetchMyContacts() {
myContacts = new HashMap<>();
Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
if (cursor != null && !cursor.isClosed()) {
cursor.getCount();
while (cursor.moveToNext()) {
int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
if (hasPhoneNumber == 1) {
String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replaceAll("\s+", "");
String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
if (Patterns.PHONE.matcher(number).matches()) {
boolean hasPlus = String.valueOf(number.charAt(0)).equals("+");
number = number.replaceAll("[\D]", "");
if (hasPlus) {
number = "+" + number;
}
Contact contact = new Contact(number, name);
String endTrim = Helper.getEndTrim(contact.getPhoneNumber());
if (!myContacts.containsKey(endTrim))
myContacts.put(endTrim, contact);
}
}
}
cursor.close();
}
}
}









share|improve this question































    -1















    I have this FetchMyUsersService Class, This class gets only users on my contact list, how i can get all Firebase users ? Please Help.



    This is my Code



    This is Dont written by me.



    I Have more classes, but i think this my solution in this class, If not just tell me i share another classes on this project



    public class FetchMyUsersService extends IntentService {
    private static String EXTRA_PARAM1 = "my_id";
    private static String EXTRA_PARAM2 = "token";
    private HashMap<String, Contact> myContacts;
    private ArrayList<User> myUsers;
    private String myId, idToken;

    public static boolean STARTED = false;

    public FetchMyUsersService() {
    super("FetchMyUsersService");
    }

    public static void startMyUsersService(Context context, String myId, String idToken) {
    Intent intent = new Intent(context, FetchMyUsersService.class);
    intent.putExtra(EXTRA_PARAM1, myId);
    intent.putExtra(EXTRA_PARAM2, idToken);
    context.startService(intent);
    }


    @Override
    protected void onHandleIntent(Intent intent) {
    STARTED = true;
    myId = intent.getStringExtra(EXTRA_PARAM1);
    idToken = intent.getStringExtra(EXTRA_PARAM2);
    fetchMyContacts();
    broadcastMyContacts();
    fetchMyUsers();
    broadcastMyUsers();
    STARTED = false;
    }

    private void broadcastMyUsers() {
    if (this.myUsers != null) {
    Intent intent = new Intent(Helper.BROADCAST_MY_USERS);
    intent.putParcelableArrayListExtra("data", this.myUsers);
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.sendBroadcast(intent);
    }
    }

    private void fetchMyUsers() {
    myUsers = new ArrayList<>();
    try {
    StringBuilder response = new StringBuilder();
    URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
    URLConnection conn = url.openConnection();
    BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String line;
    while ((line = rd.readLine()) != null) {
    response.append(line).append(" ");
    }
    rd.close();

    JSONObject responseObject = new JSONObject(response.toString());
    Gson gson = new GsonBuilder().create();
    Iterator<String> keys = responseObject.keys();
    while (keys.hasNext()) {
    String key = keys.next();
    JSONObject innerJObject = responseObject.getJSONObject(key);
    User user = gson.fromJson(innerJObject.toString(), User.class);
    if (User.validate(user) && !user.getId().equals(myId)) {
    String idTrim = Helper.getEndTrim(user.getId());
    if (myContacts.containsKey(idTrim)) {
    user.setNameInPhone(myContacts.get(idTrim).getName());
    myUsers.add(user);
    }
    }
    if (myUsers.size() == myContacts.size()) {
    break;
    }
    }

    Collections.sort(myUsers, new Comparator<User>() {
    @Override
    public int compare(User user1, User user2) {
    return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
    }
    });
    } catch (IOException e) {
    e.printStackTrace();
    } catch (JSONException e) {
    e.printStackTrace();
    }
    }

    private void broadcastMyContacts() {
    if (this.myContacts != null) {
    new Helper(this).setMyUsersNameCache(myContacts);
    Intent intent = new Intent(Helper.BROADCAST_MY_CONTACTS);
    intent.putExtra("data", this.myContacts);
    LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
    localBroadcastManager.sendBroadcast(intent);
    }
    }

    private void fetchMyContacts() {
    myContacts = new HashMap<>();
    Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
    if (cursor != null && !cursor.isClosed()) {
    cursor.getCount();
    while (cursor.moveToNext()) {
    int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
    if (hasPhoneNumber == 1) {
    String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replaceAll("\s+", "");
    String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
    if (Patterns.PHONE.matcher(number).matches()) {
    boolean hasPlus = String.valueOf(number.charAt(0)).equals("+");
    number = number.replaceAll("[\D]", "");
    if (hasPlus) {
    number = "+" + number;
    }
    Contact contact = new Contact(number, name);
    String endTrim = Helper.getEndTrim(contact.getPhoneNumber());
    if (!myContacts.containsKey(endTrim))
    myContacts.put(endTrim, contact);
    }
    }
    }
    cursor.close();
    }
    }
    }









    share|improve this question



























      -1












      -1








      -1








      I have this FetchMyUsersService Class, This class gets only users on my contact list, how i can get all Firebase users ? Please Help.



      This is my Code



      This is Dont written by me.



      I Have more classes, but i think this my solution in this class, If not just tell me i share another classes on this project



      public class FetchMyUsersService extends IntentService {
      private static String EXTRA_PARAM1 = "my_id";
      private static String EXTRA_PARAM2 = "token";
      private HashMap<String, Contact> myContacts;
      private ArrayList<User> myUsers;
      private String myId, idToken;

      public static boolean STARTED = false;

      public FetchMyUsersService() {
      super("FetchMyUsersService");
      }

      public static void startMyUsersService(Context context, String myId, String idToken) {
      Intent intent = new Intent(context, FetchMyUsersService.class);
      intent.putExtra(EXTRA_PARAM1, myId);
      intent.putExtra(EXTRA_PARAM2, idToken);
      context.startService(intent);
      }


      @Override
      protected void onHandleIntent(Intent intent) {
      STARTED = true;
      myId = intent.getStringExtra(EXTRA_PARAM1);
      idToken = intent.getStringExtra(EXTRA_PARAM2);
      fetchMyContacts();
      broadcastMyContacts();
      fetchMyUsers();
      broadcastMyUsers();
      STARTED = false;
      }

      private void broadcastMyUsers() {
      if (this.myUsers != null) {
      Intent intent = new Intent(Helper.BROADCAST_MY_USERS);
      intent.putParcelableArrayListExtra("data", this.myUsers);
      LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
      localBroadcastManager.sendBroadcast(intent);
      }
      }

      private void fetchMyUsers() {
      myUsers = new ArrayList<>();
      try {
      StringBuilder response = new StringBuilder();
      URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
      URLConnection conn = url.openConnection();
      BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String line;
      while ((line = rd.readLine()) != null) {
      response.append(line).append(" ");
      }
      rd.close();

      JSONObject responseObject = new JSONObject(response.toString());
      Gson gson = new GsonBuilder().create();
      Iterator<String> keys = responseObject.keys();
      while (keys.hasNext()) {
      String key = keys.next();
      JSONObject innerJObject = responseObject.getJSONObject(key);
      User user = gson.fromJson(innerJObject.toString(), User.class);
      if (User.validate(user) && !user.getId().equals(myId)) {
      String idTrim = Helper.getEndTrim(user.getId());
      if (myContacts.containsKey(idTrim)) {
      user.setNameInPhone(myContacts.get(idTrim).getName());
      myUsers.add(user);
      }
      }
      if (myUsers.size() == myContacts.size()) {
      break;
      }
      }

      Collections.sort(myUsers, new Comparator<User>() {
      @Override
      public int compare(User user1, User user2) {
      return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
      }
      });
      } catch (IOException e) {
      e.printStackTrace();
      } catch (JSONException e) {
      e.printStackTrace();
      }
      }

      private void broadcastMyContacts() {
      if (this.myContacts != null) {
      new Helper(this).setMyUsersNameCache(myContacts);
      Intent intent = new Intent(Helper.BROADCAST_MY_CONTACTS);
      intent.putExtra("data", this.myContacts);
      LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
      localBroadcastManager.sendBroadcast(intent);
      }
      }

      private void fetchMyContacts() {
      myContacts = new HashMap<>();
      Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
      if (cursor != null && !cursor.isClosed()) {
      cursor.getCount();
      while (cursor.moveToNext()) {
      int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
      if (hasPhoneNumber == 1) {
      String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replaceAll("\s+", "");
      String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
      if (Patterns.PHONE.matcher(number).matches()) {
      boolean hasPlus = String.valueOf(number.charAt(0)).equals("+");
      number = number.replaceAll("[\D]", "");
      if (hasPlus) {
      number = "+" + number;
      }
      Contact contact = new Contact(number, name);
      String endTrim = Helper.getEndTrim(contact.getPhoneNumber());
      if (!myContacts.containsKey(endTrim))
      myContacts.put(endTrim, contact);
      }
      }
      }
      cursor.close();
      }
      }
      }









      share|improve this question
















      I have this FetchMyUsersService Class, This class gets only users on my contact list, how i can get all Firebase users ? Please Help.



      This is my Code



      This is Dont written by me.



      I Have more classes, but i think this my solution in this class, If not just tell me i share another classes on this project



      public class FetchMyUsersService extends IntentService {
      private static String EXTRA_PARAM1 = "my_id";
      private static String EXTRA_PARAM2 = "token";
      private HashMap<String, Contact> myContacts;
      private ArrayList<User> myUsers;
      private String myId, idToken;

      public static boolean STARTED = false;

      public FetchMyUsersService() {
      super("FetchMyUsersService");
      }

      public static void startMyUsersService(Context context, String myId, String idToken) {
      Intent intent = new Intent(context, FetchMyUsersService.class);
      intent.putExtra(EXTRA_PARAM1, myId);
      intent.putExtra(EXTRA_PARAM2, idToken);
      context.startService(intent);
      }


      @Override
      protected void onHandleIntent(Intent intent) {
      STARTED = true;
      myId = intent.getStringExtra(EXTRA_PARAM1);
      idToken = intent.getStringExtra(EXTRA_PARAM2);
      fetchMyContacts();
      broadcastMyContacts();
      fetchMyUsers();
      broadcastMyUsers();
      STARTED = false;
      }

      private void broadcastMyUsers() {
      if (this.myUsers != null) {
      Intent intent = new Intent(Helper.BROADCAST_MY_USERS);
      intent.putParcelableArrayListExtra("data", this.myUsers);
      LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
      localBroadcastManager.sendBroadcast(intent);
      }
      }

      private void fetchMyUsers() {
      myUsers = new ArrayList<>();
      try {
      StringBuilder response = new StringBuilder();
      URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
      URLConnection conn = url.openConnection();
      BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
      String line;
      while ((line = rd.readLine()) != null) {
      response.append(line).append(" ");
      }
      rd.close();

      JSONObject responseObject = new JSONObject(response.toString());
      Gson gson = new GsonBuilder().create();
      Iterator<String> keys = responseObject.keys();
      while (keys.hasNext()) {
      String key = keys.next();
      JSONObject innerJObject = responseObject.getJSONObject(key);
      User user = gson.fromJson(innerJObject.toString(), User.class);
      if (User.validate(user) && !user.getId().equals(myId)) {
      String idTrim = Helper.getEndTrim(user.getId());
      if (myContacts.containsKey(idTrim)) {
      user.setNameInPhone(myContacts.get(idTrim).getName());
      myUsers.add(user);
      }
      }
      if (myUsers.size() == myContacts.size()) {
      break;
      }
      }

      Collections.sort(myUsers, new Comparator<User>() {
      @Override
      public int compare(User user1, User user2) {
      return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
      }
      });
      } catch (IOException e) {
      e.printStackTrace();
      } catch (JSONException e) {
      e.printStackTrace();
      }
      }

      private void broadcastMyContacts() {
      if (this.myContacts != null) {
      new Helper(this).setMyUsersNameCache(myContacts);
      Intent intent = new Intent(Helper.BROADCAST_MY_CONTACTS);
      intent.putExtra("data", this.myContacts);
      LocalBroadcastManager localBroadcastManager = LocalBroadcastManager.getInstance(this);
      localBroadcastManager.sendBroadcast(intent);
      }
      }

      private void fetchMyContacts() {
      myContacts = new HashMap<>();
      Cursor cursor = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, null, null, null);
      if (cursor != null && !cursor.isClosed()) {
      cursor.getCount();
      while (cursor.moveToNext()) {
      int hasPhoneNumber = cursor.getInt(cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
      if (hasPhoneNumber == 1) {
      String number = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER)).replaceAll("\s+", "");
      String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME_PRIMARY));
      if (Patterns.PHONE.matcher(number).matches()) {
      boolean hasPlus = String.valueOf(number.charAt(0)).equals("+");
      number = number.replaceAll("[\D]", "");
      if (hasPlus) {
      number = "+" + number;
      }
      Contact contact = new Contact(number, name);
      String endTrim = Helper.getEndTrim(contact.getPhoneNumber());
      if (!myContacts.containsKey(endTrim))
      myContacts.put(endTrim, contact);
      }
      }
      }
      cursor.close();
      }
      }
      }






      android firebase firebase-realtime-database






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 7:29









      Doug Stevenson

      83.4k10100118




      83.4k10100118










      asked Nov 22 '18 at 7:27









      Cabrail KerimovCabrail Kerimov

      31




      31
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Please try changing the code of your fetchMyUsers() like bellow



           private void fetchMyUsers() {
          myUsers = new ArrayList<>();
          try {
          StringBuilder response = new StringBuilder();
          URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
          URLConnection conn = url.openConnection();
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
          response.append(line).append(" ");
          }
          rd.close();

          JSONObject responseObject = new JSONObject(response.toString());
          Gson gson = new GsonBuilder().create();
          Iterator<String> keys = responseObject.keys();
          while (keys.hasNext()) {
          String key = keys.next();
          JSONObject innerJObject = responseObject.getJSONObject(key);
          User user = gson.fromJson(innerJObject.toString(), User.class);
          myUsers.add(user);
          if (myUsers.size() == myContacts.size()) {
          break;
          }
          }

          Collections.sort(myUsers, new Comparator<User>() {
          @Override
          public int compare(User user1, User user2) {
          return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
          }
          });
          } catch (IOException e) {
          e.printStackTrace();
          } catch (JSONException e) {
          e.printStackTrace();
          }
          }





          share|improve this answer
























          • Thanks Dhaval Solanki, this is working, thank you,

            – Cabrail Kerimov
            Nov 22 '18 at 7:48












          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%2f53425829%2fhow-to-get-all-registered-users-not-only-my-contact-lists-on-firebase-in-my-cod%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          Please try changing the code of your fetchMyUsers() like bellow



           private void fetchMyUsers() {
          myUsers = new ArrayList<>();
          try {
          StringBuilder response = new StringBuilder();
          URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
          URLConnection conn = url.openConnection();
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
          response.append(line).append(" ");
          }
          rd.close();

          JSONObject responseObject = new JSONObject(response.toString());
          Gson gson = new GsonBuilder().create();
          Iterator<String> keys = responseObject.keys();
          while (keys.hasNext()) {
          String key = keys.next();
          JSONObject innerJObject = responseObject.getJSONObject(key);
          User user = gson.fromJson(innerJObject.toString(), User.class);
          myUsers.add(user);
          if (myUsers.size() == myContacts.size()) {
          break;
          }
          }

          Collections.sort(myUsers, new Comparator<User>() {
          @Override
          public int compare(User user1, User user2) {
          return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
          }
          });
          } catch (IOException e) {
          e.printStackTrace();
          } catch (JSONException e) {
          e.printStackTrace();
          }
          }





          share|improve this answer
























          • Thanks Dhaval Solanki, this is working, thank you,

            – Cabrail Kerimov
            Nov 22 '18 at 7:48
















          0














          Please try changing the code of your fetchMyUsers() like bellow



           private void fetchMyUsers() {
          myUsers = new ArrayList<>();
          try {
          StringBuilder response = new StringBuilder();
          URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
          URLConnection conn = url.openConnection();
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
          response.append(line).append(" ");
          }
          rd.close();

          JSONObject responseObject = new JSONObject(response.toString());
          Gson gson = new GsonBuilder().create();
          Iterator<String> keys = responseObject.keys();
          while (keys.hasNext()) {
          String key = keys.next();
          JSONObject innerJObject = responseObject.getJSONObject(key);
          User user = gson.fromJson(innerJObject.toString(), User.class);
          myUsers.add(user);
          if (myUsers.size() == myContacts.size()) {
          break;
          }
          }

          Collections.sort(myUsers, new Comparator<User>() {
          @Override
          public int compare(User user1, User user2) {
          return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
          }
          });
          } catch (IOException e) {
          e.printStackTrace();
          } catch (JSONException e) {
          e.printStackTrace();
          }
          }





          share|improve this answer
























          • Thanks Dhaval Solanki, this is working, thank you,

            – Cabrail Kerimov
            Nov 22 '18 at 7:48














          0












          0








          0







          Please try changing the code of your fetchMyUsers() like bellow



           private void fetchMyUsers() {
          myUsers = new ArrayList<>();
          try {
          StringBuilder response = new StringBuilder();
          URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
          URLConnection conn = url.openConnection();
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
          response.append(line).append(" ");
          }
          rd.close();

          JSONObject responseObject = new JSONObject(response.toString());
          Gson gson = new GsonBuilder().create();
          Iterator<String> keys = responseObject.keys();
          while (keys.hasNext()) {
          String key = keys.next();
          JSONObject innerJObject = responseObject.getJSONObject(key);
          User user = gson.fromJson(innerJObject.toString(), User.class);
          myUsers.add(user);
          if (myUsers.size() == myContacts.size()) {
          break;
          }
          }

          Collections.sort(myUsers, new Comparator<User>() {
          @Override
          public int compare(User user1, User user2) {
          return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
          }
          });
          } catch (IOException e) {
          e.printStackTrace();
          } catch (JSONException e) {
          e.printStackTrace();
          }
          }





          share|improve this answer













          Please try changing the code of your fetchMyUsers() like bellow



           private void fetchMyUsers() {
          myUsers = new ArrayList<>();
          try {
          StringBuilder response = new StringBuilder();
          URL url = new URL(FirebaseDatabase.getInstance().getReference().toString() + "/" + Helper.REF_USERS + ".json?auth=" + idToken);
          URLConnection conn = url.openConnection();
          BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
          String line;
          while ((line = rd.readLine()) != null) {
          response.append(line).append(" ");
          }
          rd.close();

          JSONObject responseObject = new JSONObject(response.toString());
          Gson gson = new GsonBuilder().create();
          Iterator<String> keys = responseObject.keys();
          while (keys.hasNext()) {
          String key = keys.next();
          JSONObject innerJObject = responseObject.getJSONObject(key);
          User user = gson.fromJson(innerJObject.toString(), User.class);
          myUsers.add(user);
          if (myUsers.size() == myContacts.size()) {
          break;
          }
          }

          Collections.sort(myUsers, new Comparator<User>() {
          @Override
          public int compare(User user1, User user2) {
          return user1.getNameToDisplay().compareToIgnoreCase(user2.getNameToDisplay());
          }
          });
          } catch (IOException e) {
          e.printStackTrace();
          } catch (JSONException e) {
          e.printStackTrace();
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 7:40









          Dhaval SolankiDhaval Solanki

          2,81311526




          2,81311526













          • Thanks Dhaval Solanki, this is working, thank you,

            – Cabrail Kerimov
            Nov 22 '18 at 7:48



















          • Thanks Dhaval Solanki, this is working, thank you,

            – Cabrail Kerimov
            Nov 22 '18 at 7:48

















          Thanks Dhaval Solanki, this is working, thank you,

          – Cabrail Kerimov
          Nov 22 '18 at 7:48





          Thanks Dhaval Solanki, this is working, thank you,

          – Cabrail Kerimov
          Nov 22 '18 at 7:48




















          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%2f53425829%2fhow-to-get-all-registered-users-not-only-my-contact-lists-on-firebase-in-my-cod%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







          Popular posts from this blog

          How to change which sound is reproduced for terminal bell?

          Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

          Can I use Tabulator js library in my java Spring + Thymeleaf project?