获取联系人信息和删除联系人_移动开发_编程开发_程序员俱乐部

中国优秀的程序员网站程序员频道CXYCLUB技术地图
热搜:
更多>>
 
您所在的位置: 程序员俱乐部 > 编程开发 > 移动开发 > 获取联系人信息和删除联系人

获取联系人信息和删除联系人

 2011/1/18 8:05:24  407827531  http://407827531.javaeye.com  我要评论(0)
  • 摘要:/***根据提供的ID删除数据库中相对应的项*@paramid*@paramlistId*/publicvoiddelete(Stringid){if(id.equals("")||id==null){return;}Uriuri=ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI,Integer.parseInt(id));Uri.Builderb=uri.buildUpon();b
  • 标签:
	/**
	 * 根据提供的ID删除数据库中相对应的项
	 * @param id
	 * @param listId
	 */
	public void delete(String id) {
		if(id.equals("") || id == null){
			return ;
		}
		Uri uri =  ContentUris.withAppendedId(ContactsContract.RawContacts.CONTENT_URI, Integer.parseInt(id)); 
        Uri.Builder b = uri.buildUpon();
        b.appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER,"true");
        uri = b.build();
        getContentResolver().delete(uri, null, null);
	}

	private ArrayList<String> getContactCompany(String contactId){
		// 获取该联系人组织   
		ArrayList<String> companyArrayList = new ArrayList<String>();
		 Cursor organizationCursor = getContentResolver().query(Uri.parse("content://com.android.contacts/data"),
					new String[] { "data1", "data2", "data4" },
					"contact_id="
							+ contactId
							+ " and "
							+ "mimetype='vnd.android.cursor.item/organization'",
					null, null);
		 String idd=contactId;
           int count = organizationCursor.getCount();
	       if (organizationCursor.getCount() != 0) {
		         if (organizationCursor.moveToNext()) {
			        String company = organizationCursor.getString(organizationCursor.getColumnIndex(Organization.COMPANY));
			        String title = organizationCursor.getString(organizationCursor.getColumnIndex(Organization.TITLE));
			        companyArrayList.add(company);
	                companyArrayList.add(title);
		          }
	       }
        return companyArrayList;
       
	}

/** 获取联系人头像
	 * 
	 * @param id   用户ID
	 * @return 
	 */
	Bitmap getContactBitmap(String id){
		ContentResolver cr = getContentResolver();
        Uri uri = ContentUris.withAppendedId(ContactsContract.Contacts.CONTENT_URI,
            Long.parseLong(id));
        InputStream input =
            ContactsContract.Contacts.openContactPhotoInputStream(cr, uri);
        if(input == null){
        	//Log.e("star","input is null");
        	InputStream is=getResources().openRawResource(R.drawable.users);
        	BitmapDrawable bmpDraw = null;
        	bmpDraw = new BitmapDrawable(is);
        	Bitmap aa= null;
        	aa = bmpDraw.getBitmap();
        	Bitmap newb = Bitmap.createScaledBitmap(aa, 50, 50, false);
        
        	return newb;
        } else {
        	 Bitmap contactPhoto = BitmapFactory.decodeStream(input);
        	 Bitmap newb = Bitmap.createScaledBitmap(contactPhoto, 50, 50, false);
             return newb;
        }
       
	}

	/**  获取联系人信息
	 *   
	 *   ContactsContract.Contacts.DISPLAY_NAME  姓名
	 *   Organization.COMPANY;    公司
	 *   ContactsContract.Contacts._ID  ID
	 *   
	 * @param param   
	 * @return 相关信息
	 */
	String getContactInfo(final String param){
		if(mContactCursor != null){
			
			int id = mContactCursor.getColumnIndexOrThrow(param);
			String aaString= mContactCursor.getString(id);
	    	return aaString;
		}
		return "";
	}

	/**  获取联系人电话号码
	 * 
	 * @return 电话号码
	 */
	String getContactPhoneNumber(){
		ArrayList<String> alTemp = new ArrayList<String>();
		String IsPhone = mContactCursor.getString(mContactCursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER));
		if( (Integer.parseInt(IsPhone) > 0) )
		{
			Cursor phoneNumber = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI,null,
					ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = "+ getContactInfo(ContactsContract.Contacts._ID),null, null); 
			while (phoneNumber.moveToNext())
			{
				String strPhoneNumber = phoneNumber.getString(phoneNumber.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
				alTemp.add(strPhoneNumber);
			}
			
			if(phoneNumber.moveToFirst()){
				return phoneNumber.getString(phoneNumber.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
			}
		}

		return "";
	} 
  • 相关文章
发表评论
用户名: 匿名