Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After update to Android 6.0, SQLite database crashes

Tags:

android

sqlite

I use this code to work with SQLite.

Before I update to android 6.0, it works perfectly, but now it crashes.

in MyParam class

public static SQLiteDatabase dbMyCount;
public static String DB_Path_MyCount = "/sdcard/GMS/MyCount.db";

on MainActivity

MyParam.dbMyCount = this.openOrCreateDatabase(MyParam.DB_Path_MyCount, MODE_WORLD_WRITEABLE, null);
SQL  = "CREATE TABLE IF NOT EXISTS MyCount(_id INTEGER PRIMARY KEY AUTOINCREMENT,Tdate VARCHAR,Cust VARCHAR,";
SQL += "Prog VARCHAR,CustCode VARCHAR,OpenCode VARCHAR,Memo VARCHAR)";
MyParam.dbMyCount.execSQL(SQL);

I also updated my manifast to this:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

But still got error:

Error Code : 1294 (SQLITE_CANTOPEN_ENOENT) Caused By : Specified directory or database file does not exist. (unknown error (code 1294): Could not open database)

I searched the Web and could not find any answer or solution.

Thanks.

like image 338
Gold Avatar asked Mar 26 '16 20:03

Gold


1 Answers

Please follow suggestion given by CommonsWare. But also for marshmallow i.e android 6.0 and above you need to ask for run time permissions. Please have a look at the link below

http://developer.android.com/training/permissions/requesting.html

Only specifying in the manifest in not enough as per android's new runtime permissions.

like image 99
Ragesh Ramesh Avatar answered Oct 14 '22 10:10

Ragesh Ramesh