Android联系人1--分组查询
16lz
2021-12-04
package com.xzq.grouptest;import android.app.Activity;import android.database.Cursor;import android.os.Bundle;import android.provider.ContactsContract;import android.provider.ContactsContract.Groups;import android.util.Log;public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); getContactsGroups(); getContactsGroups1(); getContactsGroups2(); } /** * 当Groups.DELETED=0的时候, 是 查询没有被删除的联系人分组 * * 当Groups.DELETED=1的时候,是查询删除的分组 * * 默认情况下查询所有的分组 * * * 数据库里你添加了组,数据是一直存在的,通过Groups.DELETED,去判断显示不显示 * */ /** * 当Groups.DELETED=0的时候, 是 查询没有被删除的联系人分组 */ public void getContactsGroups() { String[] RAW_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE, }; String RAW_CONTACTS_WHERE = ContactsContract.Groups.DELETED + " = ? "; Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, RAW_PROJECTION, RAW_CONTACTS_WHERE, new String[] { "" + 0 }, null); while (cursor.moveToNext()) { String id = cursor.getString(cursor.getColumnIndex("_id")); String title = cursor.getString(cursor.getColumnIndex("title")); Log.e("XZQ", id + " " + title); } cursor.close(); } /** * 当Groups.DELETED=1的时候,是查询删除的分组 */ public void getContactsGroups1() { String[] RAW_PROJECTION = new String[] { ContactsContract.Groups._ID, ContactsContract.Groups.TITLE, }; String RAW_CONTACTS_WHERE = ContactsContract.Groups.DELETED + " = ? "; Cursor cursor = getContentResolver().query(ContactsContract.Groups.CONTENT_URI, RAW_PROJECTION, RAW_CONTACTS_WHERE, new String[] { "" + 1 }, null); while (cursor.moveToNext()) { String id = cursor.getString(cursor.getColumnIndex("_id")); String title = cursor.getString(cursor.getColumnIndex("title")); Log.e("TAG", id + " " + title); } cursor.close(); } /** * 默认情况下查询所有的分组 */ public void getContactsGroups2() { Cursor cur = getContentResolver().query(Groups.CONTENT_URI, null, null, null, null); while (cur.moveToNext()) { int id = cur.getInt(cur.getColumnIndex(ContactsContract.Groups._ID)); String title = cur.getString(cur.getColumnIndex(ContactsContract.Groups.TITLE)); Log.e("TT", id + " " + title); } cur.close(); }}
更多相关文章
- Error:(15) No resource identifier found for attribute 'round
- eclipse 启动 Android(安卓)SDK Content Loader 异常
- Mac下完全卸载干净Android(安卓)Studio
- Android利用WebService查询手机号码归属地
- Android省电策略
- Android之根据经纬度查询位置地址名称
- Android(安卓)短信的一些关键字
- android sqlite 操作
- First day of android study