1

I have been asked to integrate some C++ code into an Android project using the NDK. I have some test C++ code up and running successfully. Now I am attempting to swap the test code for the real C++ which wants to access an SQLite database file. The original C++ executes:

fopen64 (databasefilename, "r")

where databasefilename is just the name of the file itself with no path.

So now my question is, where should I put the database in my project? assets? res? And once placed there, what path (if any) will I have to put before databasefilename in order for the fopen64 to work?

Mick
  • 8,284
  • 22
  • 81
  • 173

1 Answers1

1

You can put the seed file in assets, or in res/raw, or elsewhere. There is no built-in mechanism that will extract this seed to a writeable location. See discussion "How to unpack some files from .apk to /data/data/<package> folder while installing the .apk?" for more details.

You can use NDK AAsset_read() to access the assets from native code (see "How To Get File In Assets From Android NDK").

A viable alternative is to use an expansion file (see "How to get file data from Android expansion file in native code") and StorageManager.

You can choose one of many writeable locations: the sd card, or the private app files folder, etc. (see discussions "Android NDK Write File" and "Creating temporary files in Android with NDK").

Community
  • 1
  • 1
Alex Cohn
  • 56,089
  • 9
  • 113
  • 307