使用 Contacts.Groups._COUNT 获取联系人组时,列 _count 无效?
问题 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
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