2012-02-26 57 views
1

我試圖更改聯繫人的筆記部分,我得到了他們的電話號碼(receivedLocationSender)和日誌輸出提供了正確的名稱和ID,但idk如何獲取它替換聯繫人的「NOTES」部分..我目前擁有的東西完全沒有。我不能更新聯繫人的筆記部分

 private void displayContacts() { 
       ContentResolver contentResolver = getBaseContext().getContentResolver(); 
       ContentValues contentValues = new ContentValues(); 
       Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(receivedLocationSender)); 

       String[] projection = new String[] {PhoneLookup.DISPLAY_NAME, PhoneLookup._ID}; 

       Cursor cursor = contentResolver.query(
         uri, 
         projection, 
         null, 
         null, 
         null); 

       if(cursor!=null) { 
       while(cursor.moveToNext()){ 
        String contactName = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup.DISPLAY_NAME)); 
        String contactId = cursor.getString(cursor.getColumnIndexOrThrow(PhoneLookup._ID)); 
        contentValues.clear(); 
        String noteWhereParams = ContactsContract.CommonDataKinds.Note.NOTE; 
        String[] args = new String[] { String.valueOf(receivedLocation) }; 

        contentValues.put(ContactsContract.CommonDataKinds.Note.NOTE, receivedLocation); 
        getContentResolver().update(ContactsContract.Data.CONTENT_URI, contentValues, contactId + "=?", args); 

        Log.d(LOGTAG, "contactMatch name: " + contactName); 
        Log.d(LOGTAG, "contactMatch id: " + contactId); 
        Log.d(LOGTAG, "contactNotes : " + ContactsContract.CommonDataKinds.Note.NOTE.toString()); 
       } 
       cursor.close(); 
       } 
     } 

回答

1

之後,你有從phonelookup聯繫人ID(ID)..東西以下工作

  ContentResolver cr = this.getContentResolver(); 
      ContentValues values = new ContentValues(); 

      values.clear(); 
      String noteWhere = ContactsContract.Data.CONTACT_ID + " = ? AND " + ContactsContract.Data.MIMETYPE + " = ?"; 
      String[] noteWhereParams = new String[]{id,ContactsContract.CommonDataKinds.Note.CONTENT_ITEM_TYPE}; 
      values.put(CommonDataKinds.Note.NOTE, "NEW NOTE HERE!!!!"); 

      cr.update(ContactsContract.Data.CONTENT_URI, values, noteWhere, noteWhereParams); 

      Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null, noteWhere, noteWhereParams, null); 
      if (noteCur.moveToFirst()) { 
       String note = noteCur.getString(noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE)); 
        Log.d(LOGTAG, "notes : " + note); 
      } 
      noteCur.close(); 
+0

想通了,我希望這對你的作品傢伙.. – user1219926 2012-02-29 04:16:45

相關問題