title: Android Get Contact Picture from Call Log
body: <p>It was pretty easy to get the Contact picture when querying the  <code>People.CONTENT_URI</code>, with a simple  </p>
  
  <pre><code>People.loadContactPhoto(activity, ContentUris.withAppendedId(People.CONTENT_URI, contactId)
  </code></pre>
  
  <p>because I knew the contact Id. Now I need to do the same thing after accesing the Call log. With:</p>
  
  <pre><code>String[] strFields = {
                  android.provider.CallLog.Calls.CACHED_NAME,
                  android.provider.CallLog.Calls.NUMBER, 
                  };
  
          String strUriCalls="content://call_log/calls"; 
  
              Uri UriCalls = Uri.parse(strUriCalls); 
  
              Cursor cursorLog = this.getContentResolver().query(UriCalls, strFields, null, null, null);
  </code></pre>
  
  <p>I get the list from call log, but I can't find any way of linking this with the contact id needed to load the photo. The app works from api level 4+.</p>
  
  <p>Any help is appreciated. Thank you.</p>
  
  <p>The solution, as guided by Cristian below, that works for me is:</p>
  
  <pre><code> private long getContactIdFromNumber(String number) {
          String[] projection = new String[]{Contacts.Phones.PERSON_ID};
          Uri contactUri = Uri.withAppendedPath(Contacts.Phones.CONTENT_FILTER_URL,Uri.encode(number));
          Cursor c = getContentResolver().query(contactUri, projection, null, null, null);
  
          if (c.moveToFirst()) {
              long contactId=c.getLong(c.getColumnIndex(Contacts.Phones.PERSON_ID));
              return contactId;
          }
          return -1;
      }
  </code></pre>