获取联系人信息和删除联系人
16lz
2021-01-25
推荐安卓开发神器(里面有各种UI特效和android代码库实例)
/** * 根据提供的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 "";}
更多相关文章
- Android(安卓)intent.Action 参数值及对应功能介绍(转)
- 电话短信问题
- Android(安卓)联系人、选择联系人组件库
- Android读取SIM联系人信息
- 科大讯飞语音实现Android拨号之二
- Android(安卓)ApiDemos示例解析(120):Views->Gallery->2. People
- Phonegap联系人 获取Contacts HTML5,android
- Android(安卓)intent.Action 参数值及对应功能介绍
- java android 访问DELPHI 的DATASNAP