2014-02-11 1 views
0

나는 백업 및 연락처 데이터를 복원하기위한 프로그램을 작성 중입니다. 데이터 복원에 문제가 있습니다. 서버에서 데이터를 복원하기 전에 테이블에서 데이터를 삭제하려고하지만 ContentResolver에서 데이터를 삭제할 수 없습니다.raw_contact 및 데이터 테이블에서 데이터를 삭제하려면 어떻게해야합니까?

try { 
    JSONArray rawContacts = fillList(ContactsContract.RawContacts.CONTENT_URI); 
    JSONArray datas = fillList(ContactsContract.Data.CONTENT_URI); 
    //save json data to server 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

public JSONArray fillList(Uri uri) throws Exception { 
    JSONArray arr = new JSONArray(); 
    Cursor c = cr.query(uri, null, null, null, null); 
    if(c == null || c.getCount() == 0) { 
     Log.d("contact", "cursor is empty"); 
    } else { 
     String[] columns = c.getColumnNames(); 
     while(c.moveToNext()) { 
      JSONObject obj = new JSONObject(); 
      for(String col : columns) { 
       int index = c.getColumnIndex(col); 
       obj.put(col, index); 
      } 
      arr.put(obj); 
     } 
     c.close(); 
    } 
    return arr; 
} 
+0

스택 추적이 있습니까? –

+0

getContentResolver(). 삭제는 '삭제 된'열 0에서 1로 설정됩니다. – user1434702

답변

0

이 URI는 실제 연락처를 삭제할 수 있습니다.

  Uri uri = RawContacts.CONTENT_URI.buildUpon().appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER, "true").build(); 

      ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); 
      ops.add(ContentProviderOperation.newDelete(uri) 
        .build()); 
      try { 
       cr.applyBatch(ContactsContract.AUTHORITY, ops); 
      } catch (RemoteException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } catch (OperationApplicationException e) { 
       // TODO Auto-generated catch block 
       e.printStackTrace(); 
      } 
관련 문제