3

So, I've created a Haxe function (using the OpenFL library) that saves text and image data to the game's folder on desktop targets. A little while ago, however, I was notified in this thread that the function would not work on mobile targets. The same user, thiagojabur, also gave me a solution (scroll down in the same thread). My main problem is that I don't have a mobile device myself that I can test on (I have a Galaxy Tab4, but I haven't gotten it working with my Haxe projects). Rather than send 100 versions to someone who can test it, I've decided to ask my questions here.

The goal is to save the data into a folder with the game's App ID. For instance, if the App ID is com.potato.potatogame, then the data will be saved (on Android) in the application storage directory, in the folder /Android/data/com.potato.potatogame/. I believe I can get the first part of the path using openfl.utils.SystemPath.applicationStorageDirectory(), but I'm stuck on how to get the App ID. Does anyone know of a function which can do so?

Alternatively, I may be misunderstanding a part of the code. From the way thiagojabur used the code, it would seem that SystemPath.userDirectory() returns "/Android/data/com.potato.potatogame" on Android. Is this correct, or would I still need to build the path manually?

Any help is appreciated. Thanks in advance!

ETHproductions
  • 499
  • 5
  • 19

1 Answers1

2

In one of my apps using OpenFL in legacy mode I saved an images using following code:

static var IMAGES_PATH:String = SystemPath.documentsDirectory + "/MyAppName/";

public function saveImage() 
{
    var filename:String = IMAGES_PATH + name + ".png";

    try {
        if(!FileSystem.exists(IMAGES_PATH)) {
            FileSystem.createDirectory(IMAGES_PATH);
        }
        File.saveBytes(filename, app.canvas.bitmap.encode("png"));
    } 
    catch(e:Dynamic) {
        trace(e);
    }
}

With modern non-legacy code, I guess the path getting should be changed to lime.system.System.applicationStorageDirectory

Also if you still need to get the App ID, it can be achieved by Application.current.config.packageName

YuriK
  • 432
  • 5
  • 13