首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > 移动开发 >

依据RawContactId查询联系人信息

2012-07-20 
根据RawContactId查询联系人信息?package com.michael.utility.contactimport java.util.ArrayListimpor

根据RawContactId查询联系人信息

?

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";//存放自定义的号码,如果不是自定义的话,这个为nullprivate 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也需要读取出来//Data2Data.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那种!!不是QQIm.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));//nullString im = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA1));//IM值String customIm = cursorOfIm.getString(cursorOfIm.getColumnIndex(Im.DATA6));//自定义Im名称DATA6System.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解析出来111111111111return 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));//取出自定义的名称,如果没有就是nullHashMap<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.DATA1ContactsContract.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";//存放当前地图的ZoomLevelprivate 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;}}
?

?

?

?

热点排行