title: Restrict access to content provider
body: <p>I did not find a post which ask for the same restriction as me.</p>
  
  <p>I have an application which provides a content provider (call it main application) to other applications (call them client applications). I want restrict the access to the content provider from the client applications for support only the <em>insert</em> and maybe <em>query</em> methods.</p>
  
  <p>What I do not want:</p>
  
  <ul>
  <li>Make the content provider private because the main goal is to provide a database to client applications.</li>
  <li>Restrict the access with signatures of client applications because anyone must be able to write a client application which use the main application platform.</li>
  </ul>
  
  <p>The most obvious solution I see is to write two content provider, one with full access private of the main application, and one restricted public. But I think this is definitely not a proper way.</p>
  
  <p>According to this <a href="https://groups.google.com/forum/?fromgroups=#!topic/android-developers/-apKwmVeEvo" rel="noreferrer">Google groups post</a>, I am thinking to use <code>Binder.getCallingUid()</code> in the content provider calls to detect if the call comes from the main application or not. So I can do nothing in <em>update</em> and <em>delete</em> methods if the call does not come from the main application.</p>
  
  <p>How I can get the main application <em>UID</em> to compare? And if it is possible, is this solution  secure?</p>
  
  <p>Thanks for your advice.</p>