在Android中获得的最爱联系人 [英] Getting favourites contacts in Android

查看:115
本文介绍了在Android中获得的最爱联系人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得在Android的联系人收藏夹列表中的所有联系人。目前,我可以得到所有的组ID,包括最喜欢的组ID。但似乎没有任何接触具有组ID的喜爱组ID。

我试图让所有组ID和联系人组。打印两列表后,我发现,最喜欢的组ID是不是在联系人列表中。

 的ArrayList<字符串> favGroupId =新的ArrayList<字符串>();
        最终的String [] GROUP_PROJECTION =新的String [] {
                ContactsContract.Groups._ID,ContactsContract.Groups.TITLE};
        光标光标= getContentResolver()查询(
        ContactsContract.Groups.CONTENT_URI,GROUP_PROJECTION,空,
                空,ContactsContract.Groups.TITLE);

        而(cursor.moveToNext()){
            字符串ID = cursor.getString(光标
                    .getColumnIndex(ContactsContract.Groups._ID));
            Log.v(测试,身份证);

            字符串gTitle =(cursor.getString(光标
                    .getColumnIndex(ContactsContract.Groups.TITLE)));

            Log.v(测试,gTitle);
            如果(gTitle.contains(Favorite_)){
                gTitle =收藏夹;
                favGroupId.add(ID);
            }
        }
        cursor.close();
 

解决方案

您可以使用<一个href="http://developer.android.com/reference/android/provider/ContactsContract.ContactOptionsColumns.html#STARRED">STARRED在<字段href="http://developer.android.com/reference/android/provider/ContactsContract.Contacts.html">ContactsContract.Contact类。如果你改变你的查询:

 光标光标= this.managedQuery(
    ContactsContract.Contacts.CONTENT_URI,投影,中出演=?,
    新的String [] {1},NULL);
 

这应该返回出现在Android上默认的联系人应用程序中的收藏夹选项卡中的所有联系人的列表。

I am trying to get all contacts in the favourites list of the Android contacts. Currently, I can get all the group ids including the favourite group ID. But it seems that there is no contacts that have the group ID as the favourite group ID.

I'm trying to get All groups id and contacts in each group. After printing two list, I found that the group id of favorite is not in the contact list

ArrayList<String> favGroupId=new ArrayList<String>();
        final String[] GROUP_PROJECTION = new String[] {
                ContactsContract.Groups._ID, ContactsContract.Groups.TITLE };
        Cursor  cursor = getContentResolver().query(
        ContactsContract.Groups.CONTENT_URI, GROUP_PROJECTION, null,
                null, ContactsContract.Groups.TITLE);

        while (cursor.moveToNext()) {
            String id = cursor.getString(cursor
                    .getColumnIndex(ContactsContract.Groups._ID));
            Log.v("Test",id);

            String gTitle = (cursor.getString(cursor
                    .getColumnIndex(ContactsContract.Groups.TITLE)));

            Log.v("Test",gTitle);
            if (gTitle.contains("Favorite_")) {
                gTitle = "Favorites";
                favGroupId.add(id);
            }
        }
        cursor.close();

解决方案

You can use the STARRED field in the ContactsContract.Contact class. If you change your query to:

Cursor cursor = this.managedQuery(
    ContactsContract.Contacts.CONTENT_URI, projection, "starred=?",
    new String[] {"1"}, null);

this should return a list of all contacts that appear in the Favorites tab in the default Contacts app on Android.

这篇关于在Android中获得的最爱联系人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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