Saving to Android...this worked previously but not now.

Discussion and help for Easy Save 3
Post Reply
hughsey1973
Posts: 5
Joined: Mon Sep 13, 2021 1:58 pm

Saving to Android...this worked previously but not now.

Post by hughsey1973 »

Hello

I've used this code before to save to an android device but it no longer works. I call this function when my game ends. The function works but doesn't save to my device? Where am I going wrong?

public void ReloadApp()
{
var sheet = new ES3Spreadsheet();

// Add data to cells in the spreadsheet.
for (int col = 0; col < 1; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.firstName);
for (int col = 1; col < 2; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.lastName);
for (int col = 2; col < 3; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.companyName);
for (int col = 3; col < 4; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.emailAddress);
for (int col = 4; col < 5; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.gameTime);
for (int col = 5; col < 6; col++)
for (int row = 0; row < 1; row++)
sheet.SetCell(col, row, WinningPrize.purchase);

//Windows
//sheet.Save("C:/ACIPayAfterApp/mySheet.csv", true);

//For Android
*****THIS WORKED PREVIOUSLY******* = sheet.Save("Android/Documents/ACIPayAfterApp/mySheet.csv", true);

*****I've tried this******* = sheet.Save("mysheet.csv", true);

****and this*** = sheet.Save("ACIPayAfterApp/mySheet.csv", true);

SceneManager.LoadScene(0);
}
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving to Android...this worked previously but not now.

Post by Joel »

Hi there,

We’ve had no reports of issues with Android. If an issue occurs during saving an exception will be thrown to console. Please could you put Debug.Log calls before and after your save code and send me your logcat output so I can see what is being outputted.

Also note that there’s an error in your second attempt: you’re using “mysheet.csv” rather than “mySheet.csv”.

I also strongly recommend against using absolute paths because the path can change between versions of Android.

Finally, your last attempt is incorrect because the path will be relative to PersistentDataPath which already has the app name prefixed.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
hughsey1973
Posts: 5
Joined: Mon Sep 13, 2021 1:58 pm

Re: Saving to Android...this worked previously but not now.

Post by hughsey1973 »

Thank you for your reply.

I will add the Debug Logs when I'm back in the office tomorrow.

When I comment out the code to save for Windows and save the Windows build, the spreadsheet is saved correctly so I know the function is running as it should. It then reloads the level as it should (at the end of the function)

I built the Android app again with "mySheet.csv" but still no joy. I also checked to see if my phone is displaying Hidden files as this has caught me out in the past but it is.

I will try again tomorrow and get back to you.

Thank you

Simon
User avatar
Joel
Moodkie Staff
Posts: 4849
Joined: Wed Nov 07, 2012 10:32 pm

Re: Saving to Android...this worked previously but not now.

Post by Joel »

Hi Simon,

Just to check, how are you establishing that the file doesn’t exist? If you’re manually checking the absolute path you’ve is not the path to Application.persistentDataPath. It is /storage/emulated/0/Android/data/<packagename>/files on most Android versions (see Unity’s docs for more info: https://docs.unity3d.com/ScriptReferenc ... aPath.html).

ES3.FileExists(“mySheet.csv”) will tell you whether the file exists in the PersistentDataPath without having to manually check it.

All the best,
Joel
Joel @ Moodkie Interactive
Purchase Easy Save | Contact | Guides | Docs | Getting started
hughsey1973
Posts: 5
Joined: Mon Sep 13, 2021 1:58 pm

Re: Saving to Android...this worked previously but not now.

Post by hughsey1973 »

Hello Joel,

So after a little reading on my mobile devices forums it looks like Google have stopped granting access to the "Android/data" folder as of v11 of Android. This applied to all Android devices.

The way I got around this was to install a third party file manager (File Commander) that gave me access (not sure how).

I was then able to see that ES3 had saved my csv file (and all my other files were available)

So, i wasn't going nuts but it maybe something to take note of as I'm sure you will get others asking the same question.
Post Reply