【问题标题】:Whatsapp contacts duplicating my contact listWhatsapp 联系人复制我的联系人列表
【发布时间】:2015-12-21 10:29:13
【问题描述】:

我创建了一个小活动,用于显示手机中所有带有电话号码的联系人。但是,安装了 whatsapp 的联系人有重复项。例如,如果 John 在我的联系人列表中并且他也有一个 whatsapp 帐户,那么该列表将如下所示:

...

杰克

约翰

约翰

日本

...

这是我将光标分配给链接到列表视图的适配器的代码。

    Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
    String sortOrder = ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + " ASC";
    final Cursor cursor = getContentResolver().query(uri, null, null, null, sortOrder);

    String[] from = {ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone._ID};
    int[] to = {android.R.id.text1};
    adapter = new SimpleCursorAdapter(this, android.R.layout.simple_list_item_multiple_choice, cursor, from, to, 0);

编辑 使用此代码,我确认 ContactsContract.CommonDataKinds.Phone.TYPE 的重复项具有 0 值,这意味着它是自定义联系人 (Whatsapp)。其余为 2,表示正常接触。

我需要找出一个不使用任何联系人的查询,其中 ContactsContract.CommonDataKinds.Phone.TYPE == 0

【问题讨论】:

    标签: java android android-fragments android-studio


    【解决方案1】:

    我知道可能有点晚了。但是我遇到了同样的问题。

    根据 android documentation ,ContactsContract.CommonDataKinds.Phone.TYPE 不是指它是否是自定义联系人,而是指它是什么类型的联系人,即 Mobile(2)、Home(1) 或 Work(3)。 Whatsapp 联系人将是 2 - 移动设备。

    我使用以下函数来删除重复项(不确定是否有更好的方法):

    private boolean checkDuplicate(String position) {
        LinkedHashMap<String, Integer> map;
        Integer testNull;
    
        map=new LinkedHashMap<>();
    
        testNull=map.get(position);
        if(testNull==null) {
            testNull=1;
            map.put(position, testNull);
            return false;
        }
        else {
            testNull=testNull+1;
            if(testNull==2) {
                return true;
            }
            else {
                map.put(position, testNull);
                return false;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-12
      • 2014-03-22
      • 1970-01-01
      • 2017-09-07
      • 2011-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多