0

I need to add a configuration text file to my android app. This file needs to be accessed natively with a C library. So I need to pass it the absolute path to the folder i.e. (/data/data/(package name)/files).

I looked into putting it into resources or assets. But they don't seem to have a way to get the absolute path to the resources and assets folder. Files in assets seem to also be inside the zipped apk file so there will be problems accessing it natively in c.

Where can I put a file in my project folder so that it can be placed in the app's internal storage directory?

tamy
  • 95
  • 1
  • 12

2 Answers2

0

You can place your file in res/raw. More detail here

Update

After you place your file in raw folder, you can use Android code to get file descriptor by using openRawResourceFd(). Then pass it to native code as describe here.

mr.icetea
  • 2,607
  • 3
  • 24
  • 42
  • how can i get the absolute path to the file in res/raw? I'm not accessing it in java using R. Need to access it in c with the file path. – tamy Sep 01 '15 at 14:46
0

You need to borrow (and modify) code that unpacks files from assets. When your application starts, it will check if the file already exists, and if not, unpack the file from assets.

Please see e.g. How to copy files from 'assets' folder to sdcard?

Community
  • 1
  • 1
18446744073709551615
  • 16,368
  • 4
  • 94
  • 127
  • I thought about doing it like this but is there a more efficient way? This just copies the file from assets to internal storage, effectively having 2 copies of the same file. It would be best to just place the file there upon installation. If there's no better solution, i'll just do it this way. – tamy Sep 01 '15 at 14:38
  • You will have one packed unmodified copy and one unpacked probably modified copy of that config file. Of course, if you do not need to modify it, it is possible to find out the apk location and pass it to C code, and read the archive from the C code.... The code to read it will probably take more space than the config file itself. – 18446744073709551615 Sep 02 '15 at 08:15