Custom ContentProvider Permissions and Use from other Apps

Read Time 2 minutes

A custom content provider was discussed and implemented here earlier. Today I’ll discuss how a custom content provider can be used by other applications and how content provider permissions can be defined which other applications need to have in order to use it.

Content Provider Permissions:

Lets start with the provider permissions. Below is the modified Manifest.xml file of the MyContentProvider:

<manifest xmlns:android=""
    android:versionName="1.0" >

        android:protectionLevel="signature" />
        android:protectionLevel="signature" />

        android:label="@string/app_name" >

        <provider android:name=".MyContentProvider"

          android:writePermission="sohail.aziz.WRITE" />

We have defined two custom permissions sohail.aziz.READ and sohail.aziz.WRITE and used them as content provider’s readPermission and writePermission. By defining these permissions we made it mandatory for other apps to have these permission in order to READ (Query) and WRITE (insert, update,delete) to this content provider.

Accessing Content Provider from other Apps:

In order to access this custom content provider from other apps, we need to have following things:

  •     Name of the needed permissions if any.
  •     Content URI of all the tables we need to interact.
  •     Exact fields/Cols name of the particular table.

Lets see how can we perform CRUD operations on the MyContentProvider defined here. Content URI for the categories table defined in MyContentDescriptor will be:

Uri  categoriesUri=Uri.parse(“content://sohail.aziz.mycontentprovider/categories”);

Lets put some content values in mycontentprovider from another app, say sample.apk.


public class MainActivity extends Activity {

    protected void onCreate(Bundle savedInstanceState) {

Uri  categoriesURI=Uri.parse("content://sohail.aziz.mycontentprovider/categories");

 ContentValues vals=new ContentValues();

    /* name and status are the field name of categories table in MyContentProvider*/



Same way we can call the other CRUD operations. As discussed at the start will be required to have  sohail.aziz.READ and/or sohail.aziz.WRITE permissions.

Leave a Comment

Your email address will not be published. Required fields are marked *