Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fetch all users of my app from contact list like WhatApp does in Firebase chat app

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

like image 572
prem jangir Avatar asked Aug 09 '17 18:08

prem jangir


1 Answers

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.

like image 97
GuilhermeFGL Avatar answered Oct 24 '22 03:10

GuilhermeFGL