java - Android SQLITE, unable to open database in Marshmallow only -


i built app. (the app can save favourite items using sqlite database). tried running on android nougat , there no error. when tried running on android marshmallow, app won't open (force close) , when check error says unable open database. after that, tried running on android lollipop , there no error found.

i trace error , found on marshmallow, database not created. (i used db debugger check db). add these user permissions:

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

and nothing happened. else knows this??

**new edit
syntax check if db created or not

public dataheper(context context) {         // todo auto-generated constructor stub         this.mcontext = context;         databasepath = "data/data/"+context.getpackagename()+"/databases/data.sqlite";         databasefile = new file(databasepath);         if(!databasefile.exists())             try {                 deploydatabase(databasename, databasepath);             } catch (ioexception e) {                 e.printstacktrace();             }     }        public int gettotalquotesnofilter(){             int =0;             string query="";             cursor  cursor;             //this line produce error (on marshmallow only).             //i trace , found out db not created, thats why opendatabase produce error             database = sqlitedatabase.opendatabase(databasepath, null, sqlitedatabase.open_readwrite);                 query = "select count(quotes._id) quotes;";                 writelog.d("thangtb", "query: "+query);                 try {                     cursor =  database.rawquery(query, null);                        if (cursor != null){                         boolean bool = cursor.movetofirst();                         int j = cursor.getint(0);                         = j;                      }                      if (cursor!=null) {                         cursor.close();                     }                 } catch (exception e) {                     // todo: handle exception                 }finally{                     database.close();                 }              return i;          } 

from android m onwards, permissions needs obtained user while he/she using app, solely mentioning in manifest wont do.

it super easy implement using library.

https://github.com/googlesamples/easypermissions


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -