-1

I am currently creating an android library that uses json commands for communication with another library. I would like to extract these commands from code and save them in separate files for better readability. Where do I save those files when there is no asset directory and how do I read them?

Edit: I have found an answer to my question: how to access resources in a android library project

Jan Málek
  • 531
  • 8
  • 21

1 Answers1

0

Have a look at Internal Storage. The files saved here are only available to your app. It uses the Java File API to read an write using the FileInputStream and FileOutputStream

UPDATE: As per the discussion in the comments, OP was looking for a method to ship a JSON file with the library. In light of that:

I'm not sure if library modules support raw resources. If they do, you might want to use that but it will increase the size significantly. You could also fetch the file from a server the first time you're the library is used, keeping track of that using a SharedPreference entry.

Kartik Arora
  • 571
  • 4
  • 10
  • To my knowledge the internal storage is a place where I can save and load files only during the runtime of my program (please correct me if I am wrong). I however need a way of packing my files with a library. – Jan Málek Jan 03 '18 at 13:00
  • I'm not sure if library modules support `raw` resources. If they do, you might want to use that but it will increase the size significantly. You could also fetch the file from a server the first time you're library is used, keeping track of that using a `SharedPreference` entry. – Kartik Arora Jan 03 '18 at 14:29
  • Thank you for your comment, I think the raw folder is the way to go here. – Jan Málek Jan 03 '18 at 15:10
  • Sure thing, happy to help! :) – Kartik Arora Jan 03 '18 at 15:33