Android联系人电话号码获取重复项 [英] Android Contact Phone Numbers fetching Duplication

查看:124
本文介绍了Android联系人电话号码获取重复项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以获取每个联系人的联系人和电话号码,但是电话号码是重复的,我认为有些选项可以显示与其他应用程序(例如Viber等)链接的联系人,因此联系人可以检索重复的

I can fetch contacts and Phone Numbers of each contact but Phone Numbers are duplicate I think there is some option to show contacts linked with other apps like Viber etc so contact are retrieving duplicated

如何避免选择每个联系人的重复号码?

How can I avoid picking Duplicate Numbers of each contact ?

推荐答案

我通过使用哈希映射解决了此问题。您已将设备ID的哈希图映射到电话号码。您将每个数字添加到哈希图中,然后检查哈希图是否不包含该设备ID。

I solved this issue by using hashmap. You made hashmap of device id to phone number. You add every number into hashmap before checking if hashmap doesnot contain that device id.

通过查询以下URI获取设备ID。

Get device id by Querying following URI.

Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection = new String[]{ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME, ContactsContract.CommonDataKinds.Phone.CONTACT_ID,
            ContactsContract.CommonDataKinds.Phone.NUMBER, ContactsContract.CommonDataKinds.Phone.PHOTO_URI, ContactsContract.CommonDataKinds.Phone.TYPE, ContactsContract.CommonDataKinds.StructuredName.DISPLAY_NAME};

Hashmap<String , Contact > = new Hashmap<String , Contact>();

if (contactHashMap.containsKey(id)) {
   // skip that contact.
}
else {
    //fill your contact object.
    // get device id of contact from mobile                     
       contactHashMap.put(id, contact);
}

这样,您可以避免重复。还有另一种查询其他表的方法,该表为设备ID提供了编号。但这花费了您两个查询。上面的hashmap方法是有效的,对我来说效果很好。

In this way u can avoid duplicate. There is another way to query other table which gives number to device id. But this cost u two queries. Above hashmap method is efficient and worked well for me.

这篇关于Android联系人电话号码获取重复项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆