In this codelab, You'll learn how to quickly add a ContentProvider to your project based on your model classes simply by annotating them using the SimpleSQLProvider library.

What you'll learn

What you'll need

First this is to setup your dependencies in Gradle.
In your top level project Gradle script , add the apt plugin classpath:

     buildscript {
           repositories {
           dependencies {
               classpath ''
               classpath 'com.neenbedankt.gradle.plugins:android-apt:1.6'

Apply the apt plugin to your main project's build.gradle

           apply plugin: ''
           apply plugin: ''

Add the simple-sql-provider dependencies

           dependencies {
               compile 'com.squareup:javapoet:1.2.1'
               compile 'ckm.simple:simple_sql_provider_annotation:1.0.7'
               compile 'ckm.simple:simple_sql_provider_processor:1.0.7'

You setup your provider configurations in one class as shown below. This class is used at compile time to generate all the boilerplate code for your custom Content Provider

 name = "TodoProvider",
 authority = "mbanje.kurt.todo.AUTHORITY",
 database = "todo_database.db",
 version = 1)
public class TodoProviderConfig implements ProviderConfig {

    public UpgradeScript[] getUpdateScripts() {
        return new UpgradeScript[0];

This simply works by allowing you to annotate the class files you'd want to present as tables. In our example. we will create a table called "todo" and this will be accessible by making use of the TodoProvider we configured earlier.

@SimpleSQLTable(table = "todo",provider = "TodoProvider")
public class TodoItem {

    @SimpleSQLColumn(value = "_id",primary = true)
    public long _id;

    public String label;

    public String description;

    public boolean completed;

Once you've annotated all the classes, rebuild your project and this will create all the necessary boilerplate classes for you.
You will now need to add the generated provider class to your Android manifest file & include the authority:


You will now have access to files generated for you to access the Table prefixed with "Table" using the usual Android ContentProvider methods .e.g.
TodoItemTable for the above class. The generated files have convinience functions for you to add values to the table, e.g. getContentValues() with an instance of the TodoItemTableclass to insert into db e.g.

TodoItem objectInstance = new TodoItem(...);

You can also get back data using the convinience getRowX methods:

Cursor cursor = getContentResolver().query(TodoItemTable.CONTENT_URI,
//one row
TodoItem item = TodoItemTable.getRow(cursor,true);
//multiple rows
List items = TodoItemTable.getRows(cursor,false);   

I ported the Simple To-do list app I did way back to use this library. It uses most of the features of the library if you need some motivation.
Check the project on GitHub. If you have suggestions, create a pull request.