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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With