Using save files on android, created originally in Unity

Hi, I’m switching from Unity to Defold and currently rewriting my quiz games.

On android, I want to use the save files created in game, but I just can’t get access to the directory they are saved to.

The ads plugin I use is saving in the same location as the save files, so I know it’s possible.
From the Unity manual it states

Application.persistentDataPath points to /storage/emulated/<userid>/Android/data/<packagename>/files on most devices (some older phones might point to location on SD card if present), the path is resolved using android.content.Context.getExternalFilesDir

Any ideas please?

If it’s Unity PlayerPrefs, try this library: GitHub - AGulev/ppreader: Defold Native Extension for reading Unity PlayerPrefs (or take a look how it’s implemented)

Thank you. It seems ppreader is using the data/data/… directory on android (the one Defold is using for saves). I think I need access to the emulated directory which uses a userid.

Did you try using io library to access files in that folder? If it’s succeed then you can move to next step, you can fork extension-directories and make some modifications for getting external files dir

I haven’t tried to access the folder, but only due to the userid in the path name - I don’t have the slightest idea what that is even on my own phone!
Forking extension-directories is well beyond my skill level, but I could try to write the Java code to access android.context.Context.getExternalFilesDir based on other plugins (which may be beyond my skill level too!)

Forking a github repository is super easy. You can even make modifications directly on github. The extension already has structure just add your stuff. I believe you can do that just few minutes. But if you want to create an extension yourself then go ahead, time to practice it :slight_smile:


When I tested this extension I tested that it gets files from where unity writes its PlayerPrefs, but if you write something in some of your custom folders then it will not fit for sure.

I used the Easy Save plugin to create the save files, and it uses the persistentDataPath as the folder location for saves. You can see the files in a file browser, right along with the Unity Ads cache, so I should be able to use it - I just don’t know my way around Java, so wish me luck!

1 Like

I’m attempting to write my first extension for this based on the code for a battery extension on the Assets Portal.

Of course it doesn’t work, could somebody please have a look - it’s probably a complete mess!

Not sure but you could try this

jmethodID method = env->GetStaticMethodID(cls, "GetDirectory", "(Landroid/content/Context;)Ljava/lang/String;");

jstring return_value = (jstring)env->CallStaticObjectMethod(cls, method, dmGraphics::GetNativeAndroidActivity());
const char* dir_path = env->GetStringUTFChars(return_value, 0);
1 Like

Thank you so much - no chance I would have got there without your help!

1 Like