How to store sqlite database directly on sdcard

public DataBaseHelper(final Context context) {

    super(context, Environment.getExternalStorageDirectory()
    + File.separator+ MYDATABASE_NAME, null, MYDATABASE_VERSION);
}

**Also Add permission in android Manifest
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />**

You are providing an incomplete name in your super() call. Try using:

OpenHelper(Context context) {
    super(context, "/sdcard/"+DATABASE_NAME, null, DATABASE_VERSION);
    SQLiteDatabase.openOrCreateDatabase("/sdcard/"+DATABASE_NAME,null);

}

Other than that, you should always use Environment.getExternalStoreDirectory() to get the path to the external storage, and you should also check the state of the external storage before attempting to use it.


I created my DB with

    public DatabaseHelper(final Context context) {
    super(context, Environment.getExternalStorageDirectory()
            + File.separator + FILE_DIR
            + File.separator + DATABASE_NAME, null, DATABASE_VERSION);
}

and had no problems further on. I guess your call to super() should reference the sdcard as well.