如何在android中频繁阅读联系人

如何在android中频繁阅读联系人,android,android-contentprovider,Android,Android Contentprovider,我正试图得到一份经常被打电话的名单。内容_streequent _URI经常给你加星星,我只想经常给你 游标c=this.getContentResolver()。查询(Contacts.CONTENT\u STREQUENT\u URI, 空,空,空,空) 这可能有助于您获得正在搜索的频繁/明星联系人。我为您编写了getPhoneNumbers方法,作为如何从光标中提取信息的示例。另外,请注意,如果您从设备中删除联系人/取消启动联系人,这将不会自动更新您的ui。您需要重新同步数据。要做到这一点

我正试图得到一份经常被打电话的名单。内容_streequent _URI经常给你加星星,我只想经常给你

游标c=this.getContentResolver()。查询(Contacts.CONTENT\u STREQUENT\u URI,
空,空,空,空)

这可能有助于您获得正在搜索的频繁/明星联系人。我为您编写了getPhoneNumbers方法,作为如何从光标中提取信息的示例。另外,请注意,如果您从设备中删除联系人/取消启动联系人,这将不会自动更新您的ui。您需要重新同步数据。要做到这一点,有几种方法。在我看来,如果你只是重新蚀刻这些数据不会太糟糕,因为你可能没有太多的明星联系人。但对于更大的输入大小,您需要对该列表进行分页,并找到一种比每次获取该数据更优雅的方法

    public static List<? extends ContactsModel> getFreqContacts(Context context) {
        List<ContactsModel> contacts = new ArrayList<>();
        ContentResolver contentResolver = context.getContentResolver();
        Cursor cursor = contentResolver.query(ContactsContract.Contacts.CONTENT_URI, null, "starred=?", new String[]{"1"}, "upper(" + ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME + ") ASC");

        if(cursor.getCount() > 0) {
            while (cursor.moveToNext()) {
                final String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                final String contact_id = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
                final Set<String> phone_numbers = getContactPhoneNumber(contentResolver, cursor, contact_id);
                final Set<String> emails = getContactEmailAddress(contentResolver, contact_id);

                 // do whatever you want. Now you have the phone numbers and emails of the contacts you want
             }
         }
         cursor.close();

         Collections.sort(faveContactsModels);
         return faveContactsModels;
     }

    private static Set<String> getContactPhoneNumber(ContentResolver contentResolver, Cursor cursor,String id) {
        Set<String> contactNumbers = new HashSet<>();
        if(Integer.parseInt(cursor.getString(
            cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER))) > 0
            ) {
             Cursor pCur = contentResolver.query(
                ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                null,
                ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "= ?",
                new String[]{id}, null
            );
            while(pCur.moveToNext()) {
                 String phoneNo = pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                contactNumbers.add(phoneNo);
            }
            pCur.close();
        }
        return contactNumbers;
    }

公共静态列表试图“过滤掉”
联系人contract.Contacts.STARRED
项目?你能告诉我如何过滤结果吗?事实上,我获得了频繁和星号联系人,但在lenevo设备上,如果我清除了频繁呼叫,本机应用程序不会显示任何频繁呼叫,但我的应用程序仍然提供频繁联系人。我不知道应该做什么查看
query
method的第3个第4个参数这将只提供我需要经常拨打的星号联系人