获取Android2.1的联系人生日字段

获取有生日信息的联系人的生日字段:
	ContentResolver cr = getContentResolver();
    	Uri uri = ContactsContract.Data.CONTENT_URI;
    	String [] projection = new String[]{Event.DATA1};
    	String selection = Data.MIMETYPE+"='"+Event.CONTENT_ITEM_TYPE+"'"+" and "+Event.TYPE+"='"+Event.TYPE_BIRTHDAY+"'";
    	Cursor cursor = cr.query(uri, projection, selection, null, null);
    	List<Contacts> listcontacts = new ArrayList<Contacts>();
    	if(cursor!=null){
    		if(cursor.moveToFirst()){
    			do{
    				Contacts contacts = new Contacts();
    				contacts.setBirthday(cursor.getString(0));
    				listcontacts.add(contacts);
    			}while(cursor.moveToNext());
    		}
    	}
    	return listcontacts;    
 
根据联系人ID获取联系人头像:
 
 private byte[] getContactPhoto(String id){
    	String photo_id = null;
    	byte[] contactIcon=null;
    	String [] projection = new String [] {ContactsContract.Contacts.PHOTO_ID};
    	String selection = ContactsContract.Contacts._ID +"='"+id+"'";
    	Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, projection, selection, null, null); 
    	if(cursor.moveToFirst()){ 
    		if(cursor.getString(0)!=null){    			
        		photo_id = cursor.getString(0);
    		}    		    		    
    	}
    	
    	String [] projection1 = new String [] {ContactsContract.Data.DATA15};
    	String selection1 = ContactsContract.Data._ID +"='"+photo_id+"'";
    	Cursor cursor1 = getContentResolver().query(ContactsContract.Data.CONTENT_URI, projection1, selection1, null, null);    	
    	if(cursor1.moveToFirst()){
    	       	contactIcon = cursor1.getBlob(0);
    	}
    	if(contactIcon == null){    	    
    		return null;    	    
    	}else{    	    
    		return contactIcon;    	    
    	}
    }
posted @ 2010-09-06 14:49  FigoYu  阅读(707)  评论(0编辑  收藏  举报