Source link:


The Fastest Way to create a sql based ContentProvider in Android using annotations (No reflection)



add the apt plugin as a dependency to your root build gradle as below:

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: ''

add the required dependencies as below

dependencies {

compile 'com.squareup:javapoet:1.2.0'

compile 'ckm.simple:simple_sql_provider_annotation:1.0.6'

compile 'ckm.simple:simple_sql_provider_processor:1.0.6' 


  1. Create ProviderConfig class that defines your content providers details e.g.

 name = "TestProvider",

 authority = "just.some.test_provider.authority",

 database = "test.db",

 version = 1)  public class TestProviderConfig implements ProviderConfig {


public UpgradeScript[] getUpdateScripts() {

 return new UpgradeScript[0];


This class file says - Create a ContentProvider called TestProvider - The authority for this Provider is "just.some.test_provider.authority" - The Provider uses a database file named "test.db" - The Current database version is 1 - provider UpdateScripts as a defined by the UpdateScripts class

  1. Annotate your Pojo file that defines a table in the Database as below.
  @SimpleSQLTable(table = "test", provider = "TestProvider")
public class Test {

public String myString;
 @SimpleSQLColumn(value = "col_int", primary = true)
public int anInt;
public int myinteger;
public int myshort;
public int myShort;
public long mylong;
public int myLong;
public long mydouble;
public int myDouble;
public long myfloat;
public int myFloat;
public BigDecimal bigD;
public boolean mybool;
public boolean myBool;
public Date mydateCol;


 ```  3. The rebuild your project  4. 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. TestTable 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 Test class to insert into db e.g.

 Test testInstance = new Test(...);



  To get data from the database use:


 Cursor cursor = getContentResolver().query(TestTable.CONTENT_URI,null,null,null,null);

 //one row

 Test testRow = TestTable.getRow(cursor,true);

 //multiple rows

 List<Test> testRows = TestTable.getRows(cursor,false);


  5. add your provider as usual to your AndroidManifest.xml file with a matching authority as defined in ProviderConfig class





 ##License  Apache License (Version 2.0)  You may not use this file except in compliance with the License. You may obtain a copy of the License at  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


RxTuples is a library to smooth RxJava usage by adding simple Tuple creation functions.

Custom preference view for preference screens on Android. Each social icon is selectable in the normal view. If the user clicks on the title, the dialog appears which is also clickable. Each social icon is programmed to open in the corresponding app or in the browser if the app isn't present. Including this library into your preference screen layout is very easy.

Simple Library to create RecyclerView Adapters and Viewholder in a snap.

Send any data to any Viewholder without creating custom RecyclerView Adapters.

Charter is a library to show graphics.

Simple library that helps creating a "Tap Bar" menu layout.

Card Menu View.


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes