lime
lime copied to clipboard
is there a way to access internal storage or app cache directory on android?
well, i think that i'm not first who come to you with that question, but, i'll try to explain the situation and what's the problem is with extension.
as you sayed to almost all people that asked the same question in the past: "if you find feature that lime doesn't support, then try creating an extension", so i tried making that, a little code from it:
in java: import java.io.File;
public static File getInternalStorageDir() { return Extension.mainContext.getFilesDir(); }
public static File getAppCacheDir() { return Extension.mainContext.getCacheDir(); }
in .hx file with lime.system.JNI:
public static function getInternalStorageDir() { #if android return efileSystem_getInternalStorageDir(); #end }
public static function getAppCacheDir() { #if android return efileSystem_getAppCacheDir(); #end }
#if android private static var efileSystem_getInternalStorageDir = JNI.createStaticMethod ("org.haxe.extension.Extension_fileSystem", "getInternalStorageDir", "(V)Ljava/io/File;"); private static var efileSystem_getAppCacheDir = JNI.createStaticMethod ("org.haxe.extension.Extension_fileSystem", "getAppCacheDir", "(V)Ljava/io/File;"); #end
and then i builded my app with it, but it's crashed on entering (P.S. code that calls extension's functions was not in Main or first state of the app), i checked logs, there was "fatal signal" error and a lot "File" errors (most likely that's java.io.File)
lime.system.System has no vars that can enter app cache or internal storage
i tryed a lot of another variables of code that can give me needed path, but all of them just crashed the game on entering with the same errors, so i think that's java.io.File can't be used in extension, but in that case, how can i access it? You sayed to almost all people with that question to try creating an extension, but all variables that can return needed path are crashing the game.
So, is that possible?
P.S. when i was saying "app cache directory" , i was meaning "/storage/emulated/0/android/data/$packageName/" directory
Haxe can't exactly use java.io.File
. In my experience, only basic types, strings, and arrays work well. Try returning the file path as a string.
Haxe can't exactly use
java.io.File
. In my experience, only basic types, strings, and arrays work well. Try returning the file path as a string.
already tried, but gradle daemon sayed that java.io.File cannot be converted to java.lang.String and won't build that ;-;
Java doesn't do implicit casts. You have to look up a class's documentation to find the variable or method that does the conversion you want. In this case, you want the full path (relative or absolute shouldn't matter, but you might as well go for absolute, just to be safe). So look through that page for something that will give you the absolute path in string form.