Android check contacts if they are registered in an app

前端 未结 2 643
有刺的猬
有刺的猬 2021-01-15 15:43

I need your help. I\'m developing an app which needs user to register account like Viber. What I want to include is to check if one of my contacts has already an account in

相关标签:
2条回答
  • 2021-01-15 15:59

    You can get all contacts from using code below and then send to your server:

    ArrayList<String> listAllContactName = new ArrayList<String>();
    ArrayList<String> listAllContacts = new ArrayList<String>();
    ContentResolver cr = getContentResolver();
         Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);
    
         if (cur.getCount() > 0) {
            while (cur.moveToNext()) {
                String id = cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
                String name = cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                if (Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0) {
    
        //here you can get all contact names
        listAllContactName.add(name); 
        System.out.println("name : " + name + ", ID : " + id);
    
                    // get the <span class="IL_AD" id="IL_AD4">phone number</span>
                    Cursor pCur = cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
                                           ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?",
                                           new String[]{id}, null);
                    while (pCur.moveToNext()) {
                          String phone = pCur.getString(
                                 pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                          System.out.println("phone" + phone);
    listAllContacts.add(phone);
                    }
                    pCur.close();
    
    0 讨论(0)
  • 2021-01-15 16:15

    If you are going to develop a similar app like viber.I think you can get the complete contact by susing contactsprovider and display it in a listview on clicking on a row in this listview you can pass it to your server in the server set phone number as unique field,so that you can check for match.

    0 讨论(0)
提交回复
热议问题