LiquidCore
LiquidCore copied to clipboard
LiquidCore file system and Android/iOS app
How to get direct access to the LiquidCore virtual file system from Android/iOS apps? I mean read/write files to the folder /home/public/data of LiqiudCore directly from the application without a microservice. Is this somehow possible? Thank you in advance.
Hi @boby1975 ,
The easiest way to do it is to use a method that I just added about two weeks ago -- #156
Android:
android.content.Context context = ...;
MicroService service = ...;
// Expose the Android app's files directory to LiquidCore
final String dir = context.getFilesDir().getAbsolutePath();
service.getProcess().exposeHostDirectory(dir, Process.kMediaAccessPermissionsRW);
// Write a file
final String filename = "testExposeHostFS.txt";
final String fileContents = "These are the file contents";
try (FileOutputStream fos = context.openFileOutput(filename, Context.MODE_PRIVATE)) {
fos.write(fileContents.getBytes());
}
// Tell MicroService about it
service.emitString("filesDirPath", dir);
JavaScript:
const fs = require('fs')
LiquidCore.on('filesDirPath', (path) => {
// Read the file
let contents = String(fs.readFileSync(path + '/testExposeHostFS.txt'))
console.log(contents)
}