Steps to create a Content Provider in Android

1. Define strings for provider mime type, item mime type & for authority

    <string name="[OBJECT]_CONTENT_TYPE">vnd.android.cursor.item/vnd.[initials].[object]</string>
    <string name="[OBJECT]_CONTENT_TYPE_DIR">vnd.android.cursor.dir/vnd.[initials].[object]</string>
    <string name="[OBJECT]_CONTENT_COMMENT_DIR_URI">"content://com.[initials].[object]Provider/[object]"</string>
    <string name="[OBJECT]_CONTENT_COMMENT_AUTHORITY">"com.[initials].[object]Provider"</string>

2. Create metadata class

3. Create authority and sql helper private class

4. Define authority in androidmanifest.xml

<provider android:name="[Object]Provider" android:label="@string/app_name"                      android:authorities="@string/[OBJECT]_CONTENT_COMMENT_AUTHORITY"></provider>

5. profit

That is all.

One Comment

  1. Prateek Pandey says:

    this is nice post, thanks buddy! for sharing with us.
    For another nice and understandable article related to this post check out this url link..
    http://mindstick.com/Articles/70072812-e6d0-41e4-89ab-da670d747a44/?Content%20Provider%20in%20Android
    Thanks!!

Leave a Reply

*

Contact Nixz Kerr