Matan Dahan
Matan Dahan

Reputation: 389

How To get a specific contact Note from contentresolver?

I need to get a Note of a specific contact which I have his ID and his name. Whatever I'm trying only gets me NULL at the end and im out of options after trying to find a similar answer on Google and here on SO..

PLEASE HELP :) This is the code I have:

               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();

if im adding a contact from my application and specify a Note in the Add method, the Note is being transfered and displayed successfuly

BUT if im trying to get this specific contact's Note after I close and open the application I cant get it's Note and all I get is NULL :(

The Note is visible in other contacts application so the problem is how I am trying to get the Note in my own application..

THANK YOU!

Upvotes: 0

Views: 657

Answers (1)

Matan Dahan
Matan Dahan

Reputation: 389

Got it if somone is interested..

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();
    }

Where "contactId" is the ID of the specific Contact.

Upvotes: 1

Related Questions