title: How can I call getContentResolver in android?
body: <p>I'm writing a library class to encapsulate some of my logic in my first Android app. One of the functions which I want to encapsulate is a function which queries the address book. As such, it needs a <code>ContentResolver</code>. I'm trying to figure out how to keep the library functions black-boxed... that is, to avoid having each <code>Activity</code> pass in its own context to get a <code>ContentResolver</code>. </p>
  
  <p>Problem is I cannot for the life of me figure out how to get a <code>ContentResolver</code> from within my library function. I can't find an import that contains <code>getContentResolver</code>. Googling said to use <code>getContext</code> to get a <code>Context</code> on which to call <code>getContentResolver</code>, but I can't find an import containing <code>getContext</code> either. Next posts said to use <code>getSystemService</code> to get an object to call <code>getContext</code>. BUT - I can't find any import containing <code>getSystemService</code> either! </p>
  
  <p>So I'm stuck wondering, how can I get a ContentResolver within an encapsulated library function, or am I pretty much stuck having every calling <code>Activity</code> pass in a reference to its own context?</p>
  
  <p>My code is something basically like this: </p>
  
  <pre><code>public final class MyLibrary {
      private MyLibrary() {  }
  
      // take MyGroupItem as a class representing a projection
      // containing information from the address book groups
      public static ArrayList&lt;MyGroupItem&gt; getGroups() {
          // do work here that would access the contacts
          // thus requiring the ContentResolver
      }
  }
  </code></pre>
  
  <p>getGroups is the method where I was looking to avoid having to pass in a <code>Context</code> or <code>ContentResolver</code> if I could, as I was hoping to have it cleanly black-boxed.</p>