7

I am developing a chatting app like WhatsApp using firebase. Everything is fine, but I am stuck at fetching all users who using my app from contacts like WhatsApp does... How can I fetch all users from my contact list to recyclerView

Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
prem jangir
  • 300
  • 2
  • 13
  • You can map contacts in phone and users who are registered(data which is on server) – Rahul Aug 09 '17 at 18:29
  • Check Out My Answer [Here](https://stackoverflow.com/a/64399981/13124119) or from this link https://stackoverflow.com/a/64399981/13124119 – Kamal Panara Oct 17 '20 at 07:39

1 Answers1

1

You can get a list of contacts using READ_CONTACTS permission.

Retrieving a List of Contacts

final ContentResolver cr = getContentResolver();
String[] projection = new String[] {Contacts.DISPLAY_NAME, Phone.NUMBER};
final Cursor c = cr.query(Data.CONTENT_URI, projection, null, null, null);
myCursorAdapter = new SimpleCursorAdapter(this, R.layout.list_item, c, new String[] {Phone.NUMBER}, new int[]{R.id.TVRow}, 0);
myPhoneList.setAdapter(myCursorAdapter);

myPhoneList.setOnItemClickListener(new AdapterView.OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id){
        c.moveToPosition(position);
        Toast.makeText(getApplicationContext(), c.getString(1), Toast.LENGTH_SHORT).show();
    }
});

Link to solution

Then you will need to guarantee your user set the correct phone number when register to you App. To do that i suggest a validation by SMS

Here it is a post explaining a registration with SMS validation

Just then you will know a user how has a phone number in his contact list is friend with another user in your database.

GuilhermeFGL
  • 2,891
  • 3
  • 15
  • 33
  • i have done so but how to write next code to check that the who is registered or not.. – prem jangir Aug 10 '17 at 06:01
  • To answer this I would have to write a chapter of a book. Check this post: https://www.androidhive.info/2016/10/android-working-with-firebase-realtime-database/. This post describe how to save and read a user register. Dont forget to include a `phone` member to `User` class – GuilhermeFGL Aug 10 '17 at 12:27