0

I'm building an Oculus Go app with Unity but I can't figure out how to save a txt file to the Oculus Storage. I have read everything I've found online about it, including using solutions proposed on this website here and here.

I'm trying to create a text file that records which button from a toggle group was selected by the user.

When I build the same thing for PC the code works but I can't find the files inside the Oculus Go. I have edited the OVR android manifest and have a very simple script made from following a couple of tutorials.

Any help would be appreciated, thank you!

using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using System.IO;
public class SubmitandWriteButtonOVR : MonoBehaviour

{
    //GameObject
    public ToggleGroup toggleGroup;

    public void onClick()
    {
        string selectedLabel = toggleGroup.ActiveToggles()
            .First().GetComponentsInChildren<Text>()
            .First(t => t.name == "Label").text;

        //Path of the file
        string path = Application.persistentDataPath + "/Answers.txt";

        //Create file if it doesn't exist
        if (!File.Exists(path))
        {
            File.WriteAllText(path, "Answers");
        }

        //Content of the file Get the label in activated toggles
        string content = "Selected Answers: \n" + System.DateTime.Now + "\n" + selectedLabel;

        //Add some text
        File.AppendAllText(path, content);

    }
}
LB2
  • 1
  • 1
  • whats the error message from device log? https://answers.unity.com/questions/492681/how-to-use-adb-logcat.html or try printing out that output path and check if file is actually there – mgear Dec 10 '19 at 08:32
  • @mgear Thank you for answering! Yes, I've checked the logcat but it doesn't even register. I'm not sure how I can show you the log but there are no errors and it looks as if the code wasn't even called. The button is clicked but nothing else happens. – LB2 Dec 11 '19 at 02:24

1 Answers1

0

There are several things that could be the error here:

1) Try to set your rootpath like this

rootPath = Application.persistentDataPath.Substring(0, Application.persistentDataPath.IndexOf("Android", StringComparison.Ordinal));

2) Even if your rootpath is set correctly the file might not show up. Try putting Answers.txt manually onto your GO, write something into Answers.txt from inside your App, restart your go and check again in Explorer if it wrote to your file. I read that it has to do with the Android file system not realizing that this file has been created/updated, so it doesn't show.

3) Make sure you have write permissions on externalSD via PlayerSettings

Here is my solution for a StreamWriter on Android:

private void WriteLogToFile()
    {
        Debug.Log("Starting to Write Logfile");
        string path = Path.Combine(rootPath, "Logs.txt");

        StreamWriter writer = new StreamWriter(path, true);
        writer.WriteLine("TEST");

        writer.Close();
        Debug.Log("Logging Done");
    }

Try if that, in combination with all of the tips above, helps you to reach your goal and let me know.

nrs
  • 371
  • 1
  • 9
  • Thank you for answering! I'm trying your suggestions now. However, I have another question. The OculusGo doesn't have an external SD card, only the internal memory. If I select "internal" in the player settings permissions, would this still work? – LB2 Dec 12 '19 at 05:11
  • I know it does make no sense to set it to external, but this is how it works for me on the Oculus Go. Tried with internal once, didn't work, but I don't guarantee for that. For me it's always set to external, which works just fine with Oculus Go. – nrs Dec 12 '19 at 09:00
  • I see! Thank you, I will try again and report back if I can get it to work. – LB2 Dec 17 '19 at 05:33