SQLiteAssetHelper - problems with specific phones, for example. Oneplus

I experience crashes on some devices when using SQLiteAssetHelper in my application, most of all on OnePlus devices. Now I read here that it is associated with the directory in which the database is stored.

Now I'm trying to find a workaround, the best I could come up with is currently a constructor like this

public MySubclass(Context context) { super(context, databaseName, context.getFilesDir() + "/databases", null, databaseVersion); 

Is this the right way to do this, or are there other issues with this approach?

EDIT

The exception is

 Fatal Exception: android.database.sqlite.SQLiteException: Can't upgrade read-only database from version x to y: /data/data/my.package.id/databases/database.db 

Sorry, I linked the wrong SO question: this is the right option . It says: "OnePlus can copy the database to / data / data / package -name / databases / filename.db, but it does not allow access to this data, and I have no idea about it."

+6
source share
2 answers

The SQLiteAssetHelper constructor allows you to specify your own path to the database (the folder must be writable). Unless you specify that it defaults to one. See this excerpt from the Github repo:

  if (storageDirectory != null) { mDatabasePath = storageDirectory; } else { mDatabasePath = context.getApplicationInfo().dataDir + "/databases"; } 
+2
source
 Hey you can copy database from one to another from below mentioned code. public class MySQLiteHelper extends SQLiteOpenHelper implements DBConstants { private static MySQLiteHelper mInstance = null; private SQLiteDatabase myDataBase; private static String DB_PATH = ""; public MySQLiteHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); try { if (checkDataBase()) openDataBase(); else myDataBase = this.getReadableDatabase(); } catch (Exception e) { } } public static MySQLiteHelper instance(Context context) { File outFile = context.getDatabasePath(DATABASE_NAME); DB_PATH = outFile.getPath(); if (mInstance == null) { mInstance = new MySQLiteHelper(context); } return mInstance; } 
+2
source

All Articles