- 浏览: 500831 次
- 性别:
- 来自: 福州
文章分类
- 全部博客 (165)
- iphone (2)
- android (13)
- 设计模式 (8)
- ND实习小记之Android (63)
- mac使用技巧 (1)
- window phone (1)
- 错误总结 (2)
- 开发记录 (6)
- Android控件常用属性 (7)
- 代码管理工具 (5)
- 黑莓开发 (2)
- Eclipse (9)
- Android实践项目 (6)
- 常用布局 (1)
- 自定义Widget (5)
- adapter (2)
- OsChina Android客户端研究 (1)
- android之我见 (4)
- Java相关 (1)
- 存储 (1)
- 调试 (1)
- NDK相关 (2)
- App Components (7)
- Android_提醒 (2)
- Android_存储 (0)
- Android_线程 (3)
- Android控件使用实例 (5)
- 键盘相关 (1)
- android之我见,源码 (1)
最新评论
-
xy_feng_zhi_chao:
多谢楼主分享
Android中使用styles -
michaelye1988:
soldier93 写道无关素质,我只发表自己的看法!既然你发 ...
如何在window上把你的项目提交到github -
soldier93:
无关素质,我只发表自己的看法!既然你发表了博客我就有权对其评价 ...
如何在window上把你的项目提交到github -
michaelye1988:
soldier93 写道laji 素质真低
如何在window上把你的项目提交到github -
soldier93:
laji
如何在window上把你的项目提交到github
package com.michael.utility.contact; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import com.michael.utility.JudgeLinkmanInfo; import android.content.Context; import android.database.Cursor; import android.provider.ContactsContract; import android.provider.ContactsContract.CommonDataKinds.Email; import android.provider.ContactsContract.CommonDataKinds.Event; import android.provider.ContactsContract.CommonDataKinds.GroupMembership; import android.provider.ContactsContract.CommonDataKinds.Im; import android.provider.ContactsContract.CommonDataKinds.Nickname; import android.provider.ContactsContract.CommonDataKinds.Note; import android.provider.ContactsContract.CommonDataKinds.Organization; import android.provider.ContactsContract.CommonDataKinds.Phone; import android.provider.ContactsContract.CommonDataKinds.Relation; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.Website; import android.provider.ContactsContract.Data; /** * * 根据联系人的rawContactId查询出该联系人的所有信息 * 下面是调用方法 * */ public class QueryLinkmanInfoByRawContactId { private final static String NAME = "com.michael.name";//电话类型 private final static String PHONE_TYPE = "com.michael.phone_type";//电话类型 private final static String PHONE = "com.michael.phone";//电话类型所对应的电话号码 private final static String PHONE_CUSTOM = "com.michael.phone.custom";//存放自定义的号码,如果不是自定义的话,这个为null private final static String EMAIL_TYPE = "com.michael.mail.type";//邮件 private final static String EMAIL = "com.michael.mail"; private final static String EMAIL_CUSTOM = "com.michael.mail.custom"; private final static String IM_TYPE = "com.michael.im.type";//即时消息 private final static String IM = "com.michael.im"; private final static String IM_CUSTOM = "com.michael.im.custom"; private final static String EVENT_TYPE = "com.michael.event.type";//事件 private final static String EVENT_TIME = "com.michael.event"; private final static String EVENT_CUSTOM = "com.michael.event.custom"; private final static String ADDRESS_TYPE = "com.michael.address.type";//地址 private final static String ADDRESS = "com.michael.address"; private final static String ADDRESS_CUSTOM = "com.michael.address.custom"; private final static String NOTE = "com.michael.note";//备注 private final static String NICKNAME = "com.michael.nickname";//昵称 private final static String WEBSITE = "com.michael.website";//网站 // private final static String GROUP_TYPE = "com.michael.group.type"; private final static String GROUP_NAME = "com.michael.group.name"; private final static String ORGANIZATION_TYPE = "com.michael.organization.type"; private final static String ORGANIZATION_COMPANY = "com.michael.organization.company"; private final static String ORGANIZATION_POSITION = "com.michael.organization.position"; private final static String ORGANIZATION_CUSTOM = "com.michael.organization.custom"; // private final static String RELATION_NAME = "com.michael.relation.name"; // private final static String RELATION_TYPE = "com.michael.relation,type"; private static List<HashMap<String, String>> listOfResolvedName;//姓名 private static List<HashMap<String, String>> listOfResolvedPhone;//电话 private static List<HashMap<String, String>> listOfResolvedEmail;//邮件 private static List<HashMap<String, String>> listOfResolvedNickname;//昵称 private static List<HashMap<String, String>> listOfResolvedIm;//即时通讯 private static List<HashMap<String, String>> listOfResolvedAddress;//地址 private static List<HashMap<String, String>> listOfResolvedWebsite;//网站 private static List<HashMap<String, String>> listOfResolvedEvent;//事件 private static List<HashMap<String, String>> listOfResolvedOrganization;//组织(公司) private static List<HashMap<String, String>> listOfResolvedRelation;//关系 private static List<HashMap<String, String>> listOfResolvedNote;//备注 private static List<HashMap<String, StringBuffer>> listOfResolvedGroup;//分组 private static List<HashMap<String, String>> listOfResolvedLocation;//位置 /** * 查询姓名 * */ public static List<HashMap<String, String>> queryNameInfo(Context context, String rawContactId) { Cursor cursorOfName = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Data.DISPLAY_NAME,//姓名 }, Data.RAW_CONTACT_ID + " = ? ", new String[]{ rawContactId }, null); while(cursorOfName.moveToNext()) { String name = cursorOfName.getString(cursorOfName.getColumnIndex(Data.DISPLAY_NAME)); HashMap<String, String> nameMap = new HashMap<String, String>(); nameMap.put(NAME, name); listOfResolvedName = new ArrayList<HashMap<String, String>>(); listOfResolvedName.add(nameMap); System.out.println("解析出名字:" + nameMap); } return listOfResolvedName; } /** * 查询出电话的信息 * */ public static List<HashMap<String, String>> queryPhoneInfo(Context context, String rawContactId) { Cursor cursorOfPhone = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Phone.NUMBER,//号码 Phone.TYPE,//号码类型,自定义类型是0,自定义的名称保存在data3中,所以data3也需要读取出来 Phone.DATA3,//自定义类型的名称保存在这个字段里面,如果有多个自定义,类型值都是0 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Phone.CONTENT_ITEM_TYPE, }, null); System.out.println("Cursor.getCount()" + cursorOfPhone.getCount()); //用来存放联系人信息(<电话类型,号码>) List<HashMap<String, String>> listOfPhone = new ArrayList<HashMap<String, String>>(); while(cursorOfPhone.moveToNext()) { String phoneType = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.TYPE)); String phone = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.NUMBER)); String phoneCustom = cursorOfPhone.getString(cursorOfPhone.getColumnIndex(Phone.DATA3)); HashMap<String, String> phoneMap = new HashMap<String, String>(); phoneMap.put(PHONE_TYPE, phoneType); phoneMap.put(PHONE, phone); phoneMap.put(PHONE_CUSTOM, phoneCustom); System.out.println("电话:" + phoneMap); if(phone.equals("")) { //什么都不做 } else { listOfPhone.add(phoneMap);//添加一个号码到数组中 } } cursorOfPhone.close(); // List<HashMap<String, String>> listOfResolvedPhone = new ArrayList<HashMap<String,String>>(); listOfResolvedPhone = new ArrayList<HashMap<String,String>>(); System.out.println("哈罗:listOfPhone:" + listOfPhone); listOfResolvedPhone = JudgeLinkmanInfo.getPhoneType(listOfPhone); return listOfResolvedPhone; } /** * 查询邮件信息 * * */ public static List<HashMap<String, String>> queryEmailInfo(Context context, String rawContactId) { Cursor cursorOfEmail = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Email.DATA1,//Emial地址 Email.TYPE,//号码类型,自定义类型是0,自定义的名称保存在data3中,所以data3也需要读取出来//Data2 Data.DATA3//自定义的类型名 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Email.CONTENT_ITEM_TYPE, }, null); //用来存放Email信息(邮件类型,邮件地址) List<HashMap<String, String>> listOfEmail = new ArrayList<HashMap<String, String>>(); while(cursorOfEmail.moveToNext()) { String emailType = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(ContactsContract.CommonDataKinds.Email.TYPE)); String email = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(Email.DATA1));//Email地址 String customEmail = cursorOfEmail.getString(cursorOfEmail.getColumnIndex(Email.DATA3)); HashMap<String, String> emailMap = new HashMap<String, String>(); emailMap.put(EMAIL_TYPE, emailType); emailMap.put(EMAIL, email); emailMap.put(EMAIL_CUSTOM, customEmail); System.out.println("邮件:" + emailMap); listOfEmail.add(emailMap);//添加一个号码到数组中 } cursorOfEmail.close(); // List<HashMap<String, String>> listOfResolvedEmail = new ArrayList<HashMap<String,String>>(); listOfResolvedEmail = new ArrayList<HashMap<String,String>>(); listOfResolvedEmail = JudgeLinkmanInfo.getEmailType(listOfEmail);//将Email解析出来 return listOfResolvedEmail; } /** * 查询昵称信息 * */ public static List<HashMap<String, String>> queryNicknameInfo(Context context, String rawContactId) { Cursor cursorOfNickname = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Nickname.NAME, }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Nickname.CONTENT_ITEM_TYPE, }, null); //用来存放昵称信息 // List<HashMap<String, String>> listOfNickname = new ArrayList<HashMap<String, String>>(); listOfResolvedNickname = new ArrayList<HashMap<String,String>>(); while(cursorOfNickname.moveToNext()) { String nickname = cursorOfNickname.getString(cursorOfNickname.getColumnIndex(ContactsContract.CommonDataKinds.Nickname.NAME)); if(nickname != null)//昵称不为空的时候,才添加,不如null也会被添加 { HashMap<String, String> nicknameMap = new HashMap<String, String>(); nicknameMap.put(NICKNAME, nickname); System.out.println("昵称:" + nicknameMap); listOfResolvedNickname.add(nicknameMap); } // listOfNickname.add(nicknameMap);//添加一个昵称到数组中 } cursorOfNickname.close(); return listOfResolvedNickname; } /** * 即时消息 * */ public static List<HashMap<String, String>> queryImInfo(Context context, String rawContactId) { Cursor cursorOfIm = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ Im.DATA5,//即时消息类型 Im.TYPE,//注意:这个类型指的是Home ,work那种!!不是QQ Im.DATA1,//即时消息保存的值 Im.DATA6//自定义即时消息的名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Im.CONTENT_ITEM_TYPE, }, null); //用来存放即时消息 List<HashMap<String, String>> listOfIm = new ArrayList<HashMap<String, String>>(); while(cursorOfIm.moveToNext()) { //DATA5保存的是类型,而不是TYPE,TYPE指的是家庭,单位那种。现在查询没有问题了 //IM类型为什么会是null,第一次查询不是null,保存后查询变为null,所以问题是插入失败了! String imType = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA5));//null String im = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA1));//IM值 String customIm = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA6));//自定义Im名称DATA6 System.out.println("我靠:" + cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA5))); HashMap<String, String> imMap = new HashMap<String, String>(); imMap.put(IM_TYPE, imType); imMap.put(IM, im); imMap.put(IM_CUSTOM, customIm); System.out.println("即时消息:" + imMap); listOfIm.add(imMap);//添加一个号码到数组中 } cursorOfIm.close(); listOfResolvedIm = new ArrayList<HashMap<String,String>>(); System.out.println("listOfIm:" + listOfIm);//type都变成null了 listOfResolvedIm = JudgeLinkmanInfo.getImType(listOfIm);//将Im解析出来111111111111 return listOfResolvedIm; } /** * 查询地址 * */ public static List<HashMap<String, String>> queryAddressInfo(Context context, String rawContactId) { Cursor cursorOfAddress = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.StructuredPostal.TYPE,//地址类型(单位,住宅..) StructuredPostal.DATA1,//地址的值 StructuredPostal.DATA3//自定义即时消息的名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, StructuredPostal.CONTENT_ITEM_TYPE, }, null); //用来存放地址信息 List<HashMap<String, String>> listOfAddress = new ArrayList<HashMap<String, String>>(); while(cursorOfAddress.moveToNext()) { String addressType = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(ContactsContract.CommonDataKinds.StructuredPostal.TYPE));//IM类型 String address = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(StructuredPostal.DATA1));//地址值 String customAddress = cursorOfAddress.getString(cursorOfAddress.getColumnIndex(StructuredPostal.DATA3));//自定义Im名称 HashMap<String, String> addressMap = new HashMap<String, String>(); addressMap.put(ADDRESS_TYPE, addressType); addressMap.put(ADDRESS, address); addressMap.put(ADDRESS_CUSTOM, customAddress); System.out.println("地址:" + addressMap); listOfAddress.add(addressMap);//添加一个号码到数组中 } cursorOfAddress.close(); listOfResolvedAddress = new ArrayList<HashMap<String,String>>(); listOfResolvedAddress = JudgeLinkmanInfo.getAddressType(listOfAddress);//将Im解析出来 return listOfResolvedAddress; } /** * 查询网站 * */ public static List<HashMap<String, String>> queryWebsiteInfo(Context context, String rawContactId) { Cursor cursorOfWebsite = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Website.DATA1,//网站的地址 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Website.CONTENT_ITEM_TYPE, }, null); //用来存放网站信息 // List<HashMap<String, String>> listOfWebsite = new ArrayList<HashMap<String, String>>(); listOfResolvedWebsite = new ArrayList<HashMap<String,String>>(); while(cursorOfWebsite.moveToNext()) { String website = cursorOfWebsite.getString(cursorOfWebsite.getColumnIndex(ContactsContract.CommonDataKinds.Website.DATA1)); HashMap<String, String> websiteMap = new HashMap<String, String>(); websiteMap.put(WEBSITE, website); System.out.println("网站:" + websiteMap); // listOfWebsite.add(websiteMap);//添加一个昵称到数组中 listOfResolvedWebsite.add(websiteMap); } cursorOfWebsite.close(); return listOfResolvedWebsite; } /** * 查询事件 * */ public static List<HashMap<String, String>> queryEventInfo(Context context, String rawContactId) { Cursor cursorOfEvent = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Event.START_DATE,//事件时间 Event.TYPE,//事件类型 Event.DATA3//自定义事件名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Event.CONTENT_ITEM_TYPE, }, null); //用来存放 List<HashMap<String, String>> listOfEvent = new ArrayList<HashMap<String, String>>(); while(cursorOfEvent.moveToNext()) { String eventTime = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.START_DATE));//事件时间 String eventType = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.TYPE));//事件类型,生日等等 String customEvent = cursorOfEvent.getString(cursorOfEvent.getColumnIndex(ContactsContract.CommonDataKinds.Event.DATA3));//自定义事件名称 HashMap<String, String> eventMap = new HashMap<String, String>(); eventMap.put(EVENT_TYPE, eventType); eventMap.put(EVENT_TIME, eventTime); eventMap.put(EVENT_CUSTOM, customEvent); System.out.println("事件:" + eventMap); listOfEvent.add(eventMap);//添加一个昵称到数组中 } cursorOfEvent.close(); listOfResolvedEvent = new ArrayList<HashMap<String,String>>(); listOfResolvedEvent = JudgeLinkmanInfo.getEventType(listOfEvent);//将Im解析出来 return listOfResolvedEvent; } /** * 查询组织 * */ public static List<HashMap<String, String>> queryOrganizationInfo(Context context, String rawContactId) { Cursor cursorOfOrganization = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Organization.COMPANY,//公司 Organization.TITLE,//职位 Organization.TYPE,//类型 Organization.DATA3//自定义名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Organization.CONTENT_ITEM_TYPE, }, null); System.out.println("OrganizationCount:" + cursorOfOrganization.getCount()); //用来存放 List<HashMap<String, String>> listOfOrganization = new ArrayList<HashMap<String, String>>(); while(cursorOfOrganization.moveToNext()) { String type = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.TYPE));//类型,没用了 String company = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.COMPANY));//公司 String title = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.TITLE));//职位 String customTypeName = cursorOfOrganization.getString(cursorOfOrganization.getColumnIndex(Organization.DATA3));//取出自定义的名称,如果没有就是null HashMap<String, String> organizationMap = new HashMap<String, String>(); organizationMap.put(ORGANIZATION_TYPE, type); organizationMap.put(ORGANIZATION_CUSTOM, customTypeName); organizationMap.put(ORGANIZATION_COMPANY, company); organizationMap.put(ORGANIZATION_POSITION, title); System.out.println("组织:" + organizationMap); listOfOrganization.add(organizationMap);//添加一个昵称到数组中 } cursorOfOrganization.close(); listOfResolvedOrganization = new ArrayList<HashMap<String,String>>(); listOfResolvedOrganization = JudgeLinkmanInfo.getOrganizationType(listOfOrganization);//将Im解析出来 return listOfResolvedOrganization; } /** * 查询关系 * */ private final static String RELATION_NAME = "com.michael.relation.name"; private final static String RELATION_TYPE = "com.michael.relation.type"; private final static String RELATION_CUSTOM = "com.michael.relation.custom"; // private final static String LD_RELATION_ID = ""; // private final static String LD_RELATION_TYPE = ""; // private final static String LD_RELATION_NAME = ""; public static List<HashMap<String, String>> queryRelationInfo(Context context, String rawContactId) { Cursor cursorOfRelation = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Relation.NAME,//关系 Relation.TYPE,//关系类型,父子等等 Relation.DATA3 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Relation.CONTENT_ITEM_TYPE, }, null); System.out.println("RelationCount:" + cursorOfRelation.getCount()); //用来存放 List<HashMap<String, String>> listOfRelation = new ArrayList<HashMap<String, String>>(); while(cursorOfRelation.moveToNext()) { String relationName = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.NAME));//关系中保存的字符 String relationType = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.TYPE));//关系类型 String relationCustom = cursorOfRelation.getString(cursorOfRelation.getColumnIndex(Relation.DATA3));//自定义的关系名 HashMap<String, String> relationMap = new HashMap<String, String>(); relationMap.put(RELATION_CUSTOM, relationCustom); relationMap.put(RELATION_NAME, relationName); relationMap.put(RELATION_TYPE, relationType); System.out.println("关系:" + relationMap); listOfRelation.add(relationMap);//添加一个昵称到数组中 // listOfResolvedRelation.add(relationMap); } listOfResolvedRelation = new ArrayList<HashMap<String,String>>(); listOfResolvedRelation = JudgeLinkmanInfo.getRelationType(listOfRelation); cursorOfRelation.close(); return listOfResolvedRelation; } /** * 查询备注 * */ public static List<HashMap<String, String>> queryNoteInfo(Context context, String rawContactId) { Cursor cursorOfNote = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ ContactsContract.CommonDataKinds.Note.NOTE,//备注的内容 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, Note.CONTENT_ITEM_TYPE, }, null); //用来存放备注信息 // List<HashMap<String, String>> listOfNote = new ArrayList<HashMap<String, String>>(); listOfResolvedNote = new ArrayList<HashMap<String,String>>(); while(cursorOfNote.moveToNext()) { String note = cursorOfNote.getString(cursorOfNote.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));// if(note != null)//这里要注意&& !note.equals("") { HashMap<String, String> noteMap = new HashMap<String, String>(); noteMap.put(NOTE, note); System.out.println("备注:" + noteMap); listOfResolvedNote.add(noteMap); } } cursorOfNote.close(); return listOfResolvedNote; } /** * 查询分组 * */ public static List<HashMap<String, StringBuffer>> queryGroupInfo(Context context, String rawContactId) { //群组.和Organization没有任何关系,在2.1中的数据库中有分组,但是系统没有提供实现,在4.0里面有实现 //你需要做的是,找到当前用户的GROUP_ROW_ID,根据这个GROUP_ROW_ID再去查找Group表中的TItle,这个Title就是分组的名字了 Cursor cursorOfGroup = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ // Data.DATA1 ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID,//这个是分组的名称 // GroupMembership.DATA2,//类型。0代表自定义 // GroupMembership.DATA3//自定义名称 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, GroupMembership.CONTENT_ITEM_TYPE, }, null); // listOfGroupRawId = new ArrayList<Integer>(); // listOfGroupRawTitle = new ArrayList<String>(); //用来存放 // List<HashMap<String, String>> listOfGroup = new ArrayList<HashMap<String, String>>(); StringBuffer sb = new StringBuffer(); listOfResolvedGroup = new ArrayList<HashMap<String, StringBuffer>>(); while(cursorOfGroup.moveToNext()) { //这个GroupRawId是自动增长的吗?应该是的 String groupRawId = cursorOfGroup.getString(cursorOfGroup.getColumnIndex(ContactsContract.CommonDataKinds.GroupMembership.GROUP_ROW_ID));// Cursor cursor = context.getContentResolver().query( ContactsContract.Groups.CONTENT_URI, new String[]{ // ContactsContract.Groups.ACCOUNT_TYPE, ContactsContract.Groups.TITLE }, ContactsContract.Groups._ID + " = ? ", new String[]{ groupRawId }, null ); while(cursor.moveToNext()) { // String groupType = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.ACCOUNT_TYPE)); String groupName = cursor.getString(cursor.getColumnIndex(ContactsContract.Groups.TITLE)); // HashMap<String, String> groupMap = new HashMap<String, String>(); // groupMap.put(GROUP_TYPE, groupType);// // groupMap.put(GROUP_NAME, groupName); // System.out.println("群组:" + groupName); // listOfGroup.add(groupMap); sb.append(groupName + "\n");//查询出一个就换行,优化显示效果 // sb.append(groupName); System.out.println("groupRawId:" + groupRawId + "groupName:" + groupName); // listOfGroupRawId.add(Integer.parseInt(groupRawId));//保存分组的Id // listOfGroupRawTitle.add(groupName);//保存分组的名称 } cursor.close(); } cursorOfGroup.close(); HashMap<String, StringBuffer> groupMap = new HashMap<String, StringBuffer>(); if(sb.length() != 0)//说明有分组 { sb.setLength(sb.length()-1);//去掉sb最后的两个"\n"哈哈哈,给力啊! } groupMap.put(GROUP_NAME, sb); listOfResolvedGroup.add(groupMap); return listOfResolvedGroup; } private static final String MINETYPE_LOCATION="vnd.android.cursor.item/location"; //存放经度 private static final String FIELD_LATITUDE= "data9"; //存放纬度 private static final String FIELD_LONGITUDE= "data10"; //存放当前地图的ZoomLevel private static final String FIELD_ZOOM_LEVEL = "data11"; private static final String LATITUDE_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.latitude"; private static final String LONGITUDE_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.longitude"; private static final String ZOOM_LEVEL_FROM_QUERY = "com.michael.queryLinkmanInfoByRawContactId.zoomLevel"; /** * 查询位置 * */ public static List<HashMap<String, String>> queryLocationInfo(Context context, String rawContactId) { Cursor cursorOfLocation = context.getContentResolver().query( Data.CONTENT_URI, //查询data表 new String[]{ FIELD_LATITUDE, FIELD_LONGITUDE, FIELD_ZOOM_LEVEL//经纬度和地图的缩放比例 }, Data.RAW_CONTACT_ID + " = ? and " +Data.MIMETYPE+" = ? ", new String[]{ rawContactId, MINETYPE_LOCATION, }, null); listOfResolvedLocation = new ArrayList<HashMap<String,String>>(); while(cursorOfLocation.moveToNext()) { String latitude = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_LATITUDE));// String longitude = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_LONGITUDE)); String zoomLevel = cursorOfLocation.getString(cursorOfLocation.getColumnIndex(FIELD_ZOOM_LEVEL)); if(latitude != null)//说明存在经纬度 { HashMap<String, String> locationMap = new HashMap<String, String>(); locationMap.put(LATITUDE_FROM_QUERY, latitude); locationMap.put(LONGITUDE_FROM_QUERY, longitude); locationMap.put(ZOOM_LEVEL_FROM_QUERY, zoomLevel); System.out.println("位置:" + locationMap); listOfResolvedLocation.add(locationMap); } } cursorOfLocation.close(); return listOfResolvedLocation; } }
发表评论
-
制作一个透明的Activity
2013-01-19 17:02 4274项目中遇到了这个需求,记录下来以便以后查询。顺便写出来供大家 ... -
ListView在应用开发中较为常用的做法
2013-01-14 19:25 5223首先声明下,这是本人自己使用的做法,可能并不适合每个人,但 ... -
Android中使用styles
2013-01-08 10:15 4429在项目开发中经常遇到这样的问题,在很多的Activity中都会 ... -
抽象类和接口
2012-06-11 21:06 1129接口只能定义好空的方法,不能有具体的实现,但是抽象类可以有。一 ... -
动态增加删除控件,并记住里面的内容
2012-03-29 17:53 26701.用来保存对象 private Lis ...
相关推荐
该表保存了联系人的 RawContactID、ContactID、联系次数、最后一次联系的时间、是否被添加到收藏夹、显示的名字、用于排序的汉语拼音等信息。 3. mimetypes 表 mimetypes 表用于定义所有的 MimeTypeID,即联系人的...
- `rawContactId`: 原始联系人ID,用于更精确地定位需要更新的联系人信息。 **核心代码解析**: ```java private void doNotifyLauncher(String mLookup, long rawContactId) { Intent intent = new Intent(); ...
联系人的数据库文件的位置 ...数据库中重要的几张表 1、contacts表 ...该表保存了联系人的RawContactID 、ContactID、联系次数、最后一次联系的时间、是否被添加到收藏夹、显示的名字、用于排序的汉语拼音等信息。
2. **查询联系人**:通过ContentResolver进行查询操作。以下代码示例展示如何获取所有联系人: ```java ContentResolver resolver = getContentResolver(); Cursor cursor = resolver.query(ContactsContract....
对安卓手机通讯录中的联系人进行增、删、改、查等操作,本资源只有一个java工具类,不是完整的项目,支持根据手机号查询联系人对应的RawContactId.
这段代码首先检查了是否具有读取SIM卡的权限,然后通过`getSimContacts()`获取SIM卡联系人信息,并进一步查询每个联系人的电话号码。 最后,我们可以将获取到的联系人信息展示在用户界面上,例如列表视图(ListView)...
通过这样的方式,开发者可以方便地在自己的应用中访问和修改用户的联系人信息,实现了数据的跨应用共享。同时,理解并熟练掌握ContentProvider的使用,对于Android开发人员来说至关重要,因为它可以帮助我们构建更...
在 Android 中,联系人信息是存储在 contacts2.db 数据库中的,这个数据库中有三个重要的表:data、raw_contacts 和 mimetypes。这些表之间的关系是处理联系人信息的关键。 数据表介绍 1. data 表:存储联系人的...
// 下面的操作会根据RawContacts表中已有的rawContactId使用情况自动生成新联系人的rawContactId Uri rawContactUri = context.getContentResolver().insert( RawContacts.CONTENT_URI, values); long ...
例如,查询所有联系人: ```java Cursor cursor = resolver.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null); ``` 2. 插入数据: 使用`insert()`方法插入新数据,同样需要Uri和包含新数据...
最近想写段android程序玩玩。 开发环境 eclipse ,android2.2 ...1.把通讯录中的联系人,电话号码保存到txt文件中完成备份。 2.读取txt文件,导入到通讯录完成还原。 具体代码 1.添加 通讯录读写权限,存储卡写权限 ...