title: Android get contact id from thread id
body: <p>I'm working on a simple sms app and I'm using the code below to get the thread id when loading my threads list but I can't figure out how to get the contact id using the thread id. I'm root and using root explorer I can see in the database there is a contacts table with the following columns </p>
  
  <p><code>thread_id | htcthread_id | contact_id</code></p>
  
  <p>So since I have the thread id I should be able to get the contact id but I also need to make sure this works on all devices. My app is not root by the way</p>
  
  <p>code to get thread id</p>
  
  <pre><code>Uri uri = Uri.parse("content://mms-sms/conversations?simple=true");
  Cursor c = context.getContentResolver().query(uri, null, null, null, "date desc");
  if (c.getCount() &gt; 0) {
      while (c.moveToNext()){
          //thread id is c.getString(c.getColumnIndexOrThrow("_id"))
      }
  }
  c.close
  </code></pre>