簡體   English   中英

如何從contentresolver獲取特定的聯系說明?

[英]How To get a specific contact Note from contentresolver?

我需要得到一個特定聯系人的便箋,其中包含他的ID和他的名字。 無論我在嘗試在Google以及此處找到類似的答案之后,最終只能讓我在測試結束時得到NULL,並且使我失去選擇。

請幫助:)這是我的代碼:

               Cursor noteCur = cr.query(ContactsContract.Data.CONTENT_URI, null,

          ContactsContract.CommonDataKinds.Note.CONTACT_ID+"='"+id+"'", null, null);
           noteCur.moveToFirst();
           note = noteCur.getString(
                   noteCur.getColumnIndex(ContactsContract.CommonDataKinds.Note.NOTE));
           mContactList.get(mContactList.size()-1).setNote(note);//Adding the contact Note
           System.out.println("Note " + note);
           noteCur.close();

如果即時通訊從我的應用程序添加聯系人並在Add方法中指定一個便箋,則該便箋已成功傳輸並顯示

但是如果我在關閉並打開應用程序后嘗試獲取此特定聯系人的注釋,則無法獲取注釋,而我得到的只是NULL :(

該注釋在其他聯系人應用程序中可見,因此問題是我如何嘗試在自己的應用程序中獲取該注釋。

謝謝!

如果有人感興趣的話就知道了。

try {
          Cursor cursor = contentResolver.query(
                  ContactsContract.Data.CONTENT_URI, 
                  null, 
                  CommonDataKinds.Note.CONTACT_ID +" = ?", 
                  new String[]{contactId}, null);

          while (cursor.moveToNext()) 
          {
              note = cursor.getString(cursor.getColumnIndex(CommonDataKinds.Note.NOTE));
          } 
          System.out.println("Note " + note);
          cursor.close();
          } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

其中,“ contactId”是特定聯系人的ID。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM