안 드 로 이 드 핸드폰 연락처 개발 의 첨삭 검사 개선 기능 에 대해 논 하 다.

최근 에 핸드폰 연락처 의 기능 모듈 을 만 들 때 많은 구 덩이 를 만 났 습 니 다.인터넷 에서 검색 한 이른바 가장 완전한 핸드폰 연락처 개발 에 대한 소개 에 bug 가 존재 하기 때문에 저 는 최근 의 프로젝트 소감 과 방법 을 적어 서 안 드 로 이 드 가 핸드폰 연락 처 를 개발 하 는 문턱 을 줄 이 는 데 도움 을 줄 수 있 습 니 다.좋 습 니 다.쓸데없는 말 은 하지 않 고 다음 에 주 제 를 향 해 달 려 가 겠 습 니 다.
1.핸드폰 연락처 의 전주(샤 오미 핸드폰 의 data 표 는 시 뮬 레이 터 의 data 표 와 다르다)
1.핸드폰 연락 처 는 주로 contacts 2.db 데이터베이스 시트 에 대한 조작 입 니 다.이 데이터 베이스 에는 세 개의 표 가 비교적 중요 합 니 다.각각 data,raw 입 니 다.contacts,mimetyps 이 세 개의 시계.아래 의 첨삭 검사 수정 모듈 에 서 는 주로 표 간 의 관계 에 따라 관련 된 처 리 를 한다.
1.1,data 표
 
1.2,mimetipes 표
这里写图片描述  
1.3、raw_연락처 테이블
这里写图片描述  
1.4.contacts 2.db 표를 다운로드 하 는 방법
eclipse 에서 안 드 로 이 드 시 뮬 레이 터 를 열 고 eclipse 네 비게 이 션 표시 줄 의 window->show View->other.->File Explorer.eclipse 네 비게 이 션 표시 줄 오른쪽 상단 에 있 는 DDMS,File Explorer 아래 의 data->data->com.android.providers.contact->databases 아래 에 contact2.db 데이터베이스 가 있 습 니 다.누 르 고 저장 하면 됩 니 다.
SqlLite 소프트웨어 다운로드 링크 보기
这里写图片描述  
2.심오 한 핸드폰 연락처 조회 모듈

 /**
 *           
 */
 public void number(String name1,long rawContactId) {
 //  ContentResolver       
 Cursor cursor = getContentResolver().query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
 //      ,      
 while (cursor.moveToNext()) {
  //     ID
  String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
  //        
  String contactName = cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
  if (name1.equals(contactName)) {
  //  ContentResolver              
  Cursor phone = getContentResolver().query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = " + contactId, null, null);
  if (phone.moveToNext()) {  
  String phoneNumber1 = phone.getString(phone.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));//    
  String phoneName1 = phone.getString(phone.getColumnIndex(Phone.DISPLAY_NAME));//   
  phoneNumber.setText(phoneNumber1);
  name.setText(phoneName1);
  }
  //      
  Cursor emails =getContentResolver().query(ContactsContract.CommonDataKinds.Email.CONTENT_URI,null,ContactsContract.CommonDataKinds.Email.CONTACT_ID+"="+contactId,null,null);
   while(emails.moveToNext()){
   String emailAddress =emails.getString(emails.getColumnIndex(ContactsContract.CommonDataKinds.Email.DATA));
   email.setText(emailAddress);
   }
   //  IM  
   Cursor cursorQQ =getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,ContactsContract.Data.RAW_CONTACT_ID+"="+rawContactId + " AND " + "mimetype_id=2",null,null);
   while(cursorQQ.moveToNext()){
   //      
   String im1 = cursorQQ.getString(cursorQQ.getColumnIndex(ContactsContract.CommonDataKinds.Im.DATA)); 
   qq.setText(im1);
  }
   //      
   Cursor cursorCompany =getContentResolver().query(ContactsContract.Data.CONTENT_URI,null,ContactsContract.Data.RAW_CONTACT_ID+"="+rawContactId + " AND " + "mimetype_id = 4",null,null); 
   while(cursorCompany.moveToNext()){
   String company1=cursorCompany.getString(cursorCompany.getColumnIndex("data1"));
   String position1=cursorCompany.getString(cursorCompany.getColumnIndex("data4"));
   position.setText(position1); 
   company.setText(company1);
   }
  } 
 }
}
3.심오 한 핸드폰 연락처 증가 모듈 

 //     
 public void addContact(String name, String phoneNumber,String email,String company,String position,String im) { 
 /*   raw_contacts      ,      id */ 
 /*   raw_contacts      ,      id */ 
 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts"); 
 ContentValues values = new ContentValues(); 
 long rawContactId= ContentUris.parseId(resolver.insert(uri, values)); 
 //  data  
 uri = Uri.parse("content://com.android.contacts/data"); 
 //  data      
 if (name != "") { 
  values.put("raw_contact_id", rawContactId); 
  values.put("mimetype", "vnd.android.cursor.item/name"); 
  values.put("data2", name); 
  resolver.insert(uri, values); 
 } 
 //  data        
 if ( phoneNumber != "") { 
  values.clear(); 
  values.put("raw_contact_id", rawContactId); 
  values.put("mimetype", "vnd.android.cursor.item/phone_v2"); 
  values.put("data2", "2"); 
  values.put("data1", phoneNumber); 
  resolver.insert(uri, values);
 } 
 // data      
 if (email!= "") { 
  //   Email 
  values.clear(); 
  values.put("raw_contact_id", rawContactId);
  values.put(Data.MIMETYPE, Email.CONTENT_ITEM_TYPE); 
  values.put(Email.DATA, email);
  values.put(Email.TYPE, Email.TYPE_WORK); 
  resolver.insert(uri, values); 
 }
 // data          
 if(company!=""&&position!=""){
  //organization
  values.clear(); 
  values.put(Data.RAW_CONTACT_ID, rawContactId); 
  values.put(Organization.MIMETYPE, Organization.CONTENT_ITEM_TYPE); 
  values.put(Organization.LABEL, name); 
  values.put(Organization.TITLE, position); 
  values.put(Organization.COMPANY, company); 
  values.put(Organization.TYPE,Organization.TYPE_WORK); 
  context.getContentResolver().insert(uri, values); 
 }
 // data        QQ
 if(im!=""){
  //im
  values.clear(); 
  values.put("raw_contact_id", rawContactId); 
  values.put("mimetype", "vnd.android.cursor.item/im"); 
  values.put(Im.DATA, im); 
  values.put(Im.TYPE, Im.TYPE_WORK); 
  resolver.insert(uri, values); 
 } 
 } 
4.심오 한 핸드폰 연락처 업데이트 모듈

//       
 public void updataContact(long rawContactId,String name,String number,String email,String company,String position,String im) { 
  Uri uri = Uri.parse("content://com.android.contacts/data");// data        
  ContentValues values = new ContentValues();
  //      
  values.put("data1", number);
  resolver.update(uri, values, "mimetype_id=? and raw_contact_id=?", new String[]{"5", rawContactId+""}) ;
  //       
  values.clear();
  values.put("data1", name);
  resolver.update(uri, values, "mimetype_id=? and raw_contact_id=?", new String[]{"7", rawContactId+""}) ;
  //  email
  values.clear();
  values.put("data1", email);
  resolver.update(uri, values, "mimetype_id=? and raw_contact_id=?", new String[]{"1", rawContactId+""}) ; 
  //  im
  values.clear();
  values.put("data1", im);
  resolver.update(uri, values, "mimetype_id=? and raw_contact_id=?", new String[]{"2", rawContactId+""}) ; 
  //  company
  values.clear();
  values.put("data1", company);
  values.put("data3",name);
  values.put("data4",position);
  resolver.update(uri, values, "mimetype_id=? and raw_contact_id=?", new String[]{"4", rawContactId+""}) ; 
 } 
5.심오 한 핸드폰 연락처 삭제 모듈

//       
 public void deleteContact(long rawContactId) { 
 Uri uri = Uri.parse("content://com.android.contacts/raw_contacts");
  Cursor cursor =
  resolver.query(uri,new String[]{RawContacts._ID},"contact_id=?",new String[]{String.valueOf(rawContactId) }, null ); 
  if(cursor.moveToFirst()){
  int id = cursor.getInt(0);
  resolver.delete(uri, "_id=?",new String[]{id+""});
  uri = Uri.parse("content://com.android.contacts/data");
  resolver.delete(uri, "raw_contact_id=?",new String[]{id+""});
  cursor.close();
  } 
 } 
6.핸드폰 연락처 소프트웨어 와 시스템 핸드폰 연락처 소프트웨어 의 차이 점
6.1 시스템 의 핸드폰 연락처 소프트웨어 는 단일 연락 처 를 삭제 할 때 직접 삭제 하 는 것 이 아니 라 특정한 값 을 0 으로 설정 하여 이 핸드폰 연락처 정 보 를 볼 수 없 게 한다.인터넷 의 대부분 인 스 턴 스 에 따라 data 데이터 베이스 표 에 있 는 단일 연락처 의 정 보 를 직접 삭제 했다.

좋은 웹페이지 즐겨찾기