After upgrading to Android 6.0, SQLite Database Fails

I use this code to work with SQLite.

Before I upgrade to android 6.0, it works fine, but now it crashes.

in class MyParam

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 manifest for this:

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

But the error still appeared:

Error code: 1294 (SQLITE_CANTOPEN_ENOENT) Called: The specified directory or database file does not exist. (unknown error (code 1294): Failed to open the database)

I searched the Internet and did not find an answer or solution.

Thanks.

+5
source share
1 answer

Please follow CommonsWare recommendations. But also for marshmallow ie android 6.0 and above you need to request runtime permissions. Please see the link below.

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

Specifying only in the manifest is not sufficient in accordance with the execution rights during the execution time.

+1
source

Source: https://habr.com/ru/post/1245828/


All Articles