How to Access Sqlite Database from Assets Folder in Android Example

Please follow and like us:

How to Access Sqlite Database from Assets Folder in Android ExampleReading Sqlite database file with .sqlite extension from asset folder is very easy task with the help of Latest Android Library SQLiteAssetHelper Example. With this new Android Library we can access existing Sqlite database in our Android Application.

Loading Sqlite Database from Assets Folder in Android Application

First, add required dependencies in your app’s build.gradle file.

apply plugin: ''

android {
    compileSdkVersion 24
    buildToolsVersion "24.0.0"

    defaultConfig {
        applicationId "com.sqliteassethelper.demo"
        minSdkVersion 11
        targetSdkVersion 24
        versionCode 1
        versionName "1.0"
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), ''

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile ''
    compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'

Add existing sqlite database file in Assests/Databases folder like bellow image


Create file for SQLiteAssetHelper.

package com.sqliteassethelper.demo;

import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.readystatesoftware.sqliteasset.SQLiteAssetHelper;

import java.util.ArrayList;

public class MyDatabase extends SQLiteAssetHelper {

    private static final String DATABASE_NAME = "yogalite.db";
    private static final int DATABASE_VERSION = 1;
    private static final String ID="id";
    private static final String NAME="name";
    private static final String DESCRIPTION="description";
    private static final String IMAGE="image";
    private static final String BENEFITS="benefits";
    private static final String POSES_TABLE="poses";

    public MyDatabase(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);

    public ArrayList<Poses> getPoses(){
        SQLiteDatabase db=getWritableDatabase();
        String[] columns={MyDatabase.ID,MyDatabase.NAME,MyDatabase.DESCRIPTION,MyDatabase.BENEFITS,MyDatabase.IMAGE};
//        String[] selectionArgs={categoryId+"",subjectId+"",yearId+""};
        Cursor cursor=db.query(MyDatabase.POSES_TABLE, columns, null, null, null, null, null);
//        Cursor cursor=db.query(MyDatabase.TABLE_NAME, columns, null,null, null, null, null);
        ArrayList<Poses> questionsArrayList=new ArrayList<>();

            Poses questions=new Poses();
        return questionsArrayList;


Create POJO class for DAtabase’s table Poses

package com.sqliteassethelper.demo;

public class Poses {

    public int id;

    public String name;

    public String description;

    public String benefits;

    public String image;

Initialize DatabaseHelper file and load data from sqlite database file to Application in file

package com.sqliteassethelper.demo;

import android.os.Bundle;
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    MyDatabase myDatabase;
    private ArrayList<Poses> posesArrayList;

    protected void onCreate(Bundle savedInstanceState) {
        myDatabase=new MyDatabase(MainActivity.this);


        Log.e("poses list",posesArrayList.size()+"");

        for(int i=0;i<posesArrayList.size();i++){
            Log.e(" category filter",posesArrayList.get(i).name+"");


Add write external storage permission in your AndroidMainifest.xml file.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android=""

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
        <activity android:name=".MainActivity">
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />



Final Words

Note: This demo will not work in Android 6.0. If you want it for Android 6.0 then you have to add Android Runtime permissions.
Hope you like our simple tutorial of loading sqlite database file from asset folder in Android Application.

nirav kalola