【问题标题】:Android: Get unique contacts called from the call logAndroid:获取从通话记录中调用的唯一联系人
【发布时间】:2023-03-28 17:10:01
【问题描述】:

假设我的通话记录中有 100 个通话。我想找到他们被调用的唯一联系人(不是号码)。 问题是,如果一个联系人有两个电话号码(例如,对于联系人 A,我有一个家庭电话号码和另一个电话号码),我会将该联系人计数两次!

我尝试了以下方法。 我正在阅读通话记录。然后对于每个通话记录号码,我调用以下自定义函数:

private String getContactID (String number) 
{
    String contactID = "";
    ContentResolver context = getContentResolver();

    /// number is the phone number
    Uri lookupUri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI,Uri.encode(number));

    String[] mPhoneNumberProjection = { PhoneLookup._ID };

    Cursor cur = context.query(lookupUri,mPhoneNumberProjection, null, null, null);
    try 
    {
       if (cur.moveToFirst()) 
       {
          contactID = cur.getString(0);
          return contactID;
       }
    } 
    finally 
    {
        if (cur != null)
            cur.close();
    }
    return contactID;
}

然后我有一个带有联系人 ID 和通话时间戳的通话记录,并使用 Set 我得到了唯一的... 上面的代码工作正常,但性能很差!我在新的 Google Nexus 4 中尝试过,大约需要 1600 毫秒!我不想考虑旧的智能手机...

有什么建议吗?

【问题讨论】:

标签: android performance calllog


【解决方案1】:

使用后台线程延迟加载 ListView 中的信息。

最初只获取大约 10 个结果并将它们显示在列表中。这应该很快发生。之后,在后台线程中,继续获取信息,一次 10 个,然后继续将它们添加到您的列表中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-30
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-30
    • 1970-01-01
    相关资源
    最近更新 更多