lundi 20 avril 2015

Howto read a sqlite database from external storage with lollipop

My App is based on a lot of data stored in a big sqlite file. (500MB). This Database is downloaded from a server at first start and will never change again. (Only read Access). Everything is already working, but the data is stored on the internal sdcard since KITKAT. Now with Lollipop we have new features storing the data to the external SD-Card. With this new feature I have problems.

Use Case - User starts the app the very first time

  • User will be asked in which folder the data should be stored with the new introduced ACTION_OPEN_DOCUMENT_TREE
  • The App downloads the database and stores it to the folder
  • The App shows the data.
  • User quits the app
  • User starts the app again.

Now. How can I detect which folder the User has choosen at first start ? I don't like to show the Tree Dialog again. (Do I have to store any Path in preferences myself ?)

and

How do I access the downloaded Database in that folder ?

myconnection = SQLiteDatabase.openDatabase(<MyPath>, null, SQLiteDatabase.OPEN_READONLY); // <MyPath> is like /sdcard/selectedfolder/mydatabase.sqlite

Aucun commentaire:

Enregistrer un commentaire