使用 Contacts.Groups._COUNT 获取联系人组时,列 _count 无效?

发布于 2024-08-23 06:21:03 字数 2032 浏览 5 评论 0原文

问题 1.

我有这个类:

public class ContactGroups {

    // Form an array specifying which columns to return.
    String[] projection = new String[] { Contacts.Groups._ID,
            Contacts.Groups._COUNT, Contacts.Groups.NAME, Contacts.Groups.NOTES };

    public Cursor getList(Activity act) {

        Uri contacts = Contacts.Groups.CONTENT_URI;
             // using the debugger code kills here
            Cursor managedCursor = act.managedQuery(contacts, projection, 
                null, 
                null 
             , null
                );
        return managedCursor;
    }

    public ArrayList<String> getColumnData(Cursor cur) {
        ArrayList<String> aa = new ArrayList<String>();
        if (cur.moveToFirst()) {

            String name;
            String notes;
            int nameColumn = cur.getColumnIndex(Contacts.Groups.NAME);
            int notesColumn = cur.getColumnIndex(Contacts.Groups.NOTES);

            do {
                // Get the field values
                name = cur.getString(nameColumn);
                notes = cur.getString(notesColumn);
                aa.add(name);
                // Do something with the values.

            } while (cur.moveToNext());

        }
        return aa;
    }

}

我将其称为:

ContactGroups mGrp= new ContactGroups();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,mGrp.getColumnData(mGrp.getList(this)));
myListView.setAdapter(aa);

并且有:

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

我收到“未找到源”错误 和 Logcat 错误

ERROR/DatabaseUtils(617): java.lang.IllegalArgumentException: Invalid column _count

有人知道为什么吗?

问题 2.

在哪里可以手动创建联系人群组?

Problem 1.

I have this class:

public class ContactGroups {

    // Form an array specifying which columns to return.
    String[] projection = new String[] { Contacts.Groups._ID,
            Contacts.Groups._COUNT, Contacts.Groups.NAME, Contacts.Groups.NOTES };

    public Cursor getList(Activity act) {

        Uri contacts = Contacts.Groups.CONTENT_URI;
             // using the debugger code kills here
            Cursor managedCursor = act.managedQuery(contacts, projection, 
                null, 
                null 
             , null
                );
        return managedCursor;
    }

    public ArrayList<String> getColumnData(Cursor cur) {
        ArrayList<String> aa = new ArrayList<String>();
        if (cur.moveToFirst()) {

            String name;
            String notes;
            int nameColumn = cur.getColumnIndex(Contacts.Groups.NAME);
            int notesColumn = cur.getColumnIndex(Contacts.Groups.NOTES);

            do {
                // Get the field values
                name = cur.getString(nameColumn);
                notes = cur.getString(notesColumn);
                aa.add(name);
                // Do something with the values.

            } while (cur.moveToNext());

        }
        return aa;
    }

}

I am calling this as:

ContactGroups mGrp= new ContactGroups();
final ArrayAdapter<String> aa;
aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1,mGrp.getColumnData(mGrp.getList(this)));
myListView.setAdapter(aa);

And having:

<uses-permission android:name="android.permission.READ_CONTACTS"></uses-permission>
<uses-permission android:name="android.permission.WRITE_CONTACTS"></uses-permission>

I get a Source not found error
and a Logcat error

ERROR/DatabaseUtils(617): java.lang.IllegalArgumentException: Invalid column _count

Does somebody know why?

Problem 2.

Where do I create manually contact groups?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

划一舟意中人 2024-08-30 06:21:03

Contacts.Groups 已弃用。您应该使用 ContactsContract

您可能感兴趣的常量位于 ContactsContract 下。组,尤其是 SUMMARY_COUNT 的计数

Contacts.Groups is deprecated. You should use ContactsContract.

And the constants you may be interested in are under ContactsContract.Groups, especially SUMMARY_COUNT for the count

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文