Getting Android app's directory path from Haxe code

Hello,

I need a way to get my app’s internal or external storage path while running on Android so I can read and write files. I would like to access the file contents in Haxe code or at least a way for Haxe code to tell a Java extension what data to read/write. I haven’t been able to figure that out. I read about the legacy SystemPath thing, but are there other ways?

It seems that currently I can write to files on Android with Haxe’s sys.io.File etc., but that requires that I know the correct directory path for my app beforehand. I think the path could be different on different devices, so it wouldn’t smart to rely on that path to work on other devices, or am I wrong…? I think I need a way to find the path in runtime.

I thought I could get the path in Java and pass it to Haxe, so, as an experiment, I tried to make an extension for my Lime project using “lime create extension Foo” and get an int value from the sample Foo.java extension class into Haxe via the sample Foo.hx extension class, but that fails, I was thinking maybe because the JNI implementation is outdated / not ready in OpenFL 3.2.2?

After that, I looked at lime/2,5,2/lime/utils/JNI.hx, but I can’t figure out if that can be used to make the extension Haxe/Java classes pass data to each other. When I trace(lime.utils.JNI.getEnv()) in Haxe, adb logcat shows that getEnv returns an integer but I have no idea how it should be used, and I can’t seem to find any docs or code about it. For example, trace(JNI.getEnv().createStaticMethod) returns null.

Versions I’m using:
Haxe Compiler 3.2.0
Haxe Library Manager 3.2.0-rc.3
OpenFL Command-Line Tools 3.2.2-LOKuCs
Lime Command-Line Tools (2.5.2)
FlashDevelop 5.0.1.3
Win 10

lime.system.System http://docs.openfl.org/lime/system/System.html gives access to several path, applicationStorageDirectory is probably the one you are looking for.

Oh, nice! It seems to be just what I want. I missed that one while reading the API. Thanks! I’m glad there’s a simple way to get the path.