Android检查联系人是否在应用程序中注册

时间:2015-03-16 05:31:05

标签: android

我需要你的帮助。我正在开发一个需要用户注册像Viber这样的帐户的应用程序。我想要包括的是检查我的一个联系人是否已经在Viber中拥有一个帐户。你有想法怎么做吗?我一直在谷歌搜索,没有找到任何相关的东西。

2 个答案:

答案 0 :(得分:0)

如果您要开发类似viber的类似应用程序。我认为您可以通过联系contactsprovider获取完整的联系人,并在列表视图中显示它,点击此列表视图中的一行,您可以将其传递到服务器中的服务器将电话号码设置为唯一字段,以便您可以检查匹配。

答案 1 :(得分:0)

您可以使用以下代码获取所有联系人,然后发送到您的服务器:

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();