Quantcast
Channel: Questions in topic: "webrequest"
Viewing all articles
Browse latest Browse all 387

How to use UnityWebRequest to access local text file on Andorid build

$
0
0
Hello,
I'm trying to make a simple app that chooses a random workout from a text file and will be build on Android. I've read that you can't access files with streamreaders directly because of the way the apk is compressed on Android.

I've tried using UnityWebRequest to no avail. Maybe I'm not understanding the documentation, but I can't figure out how to access a **local** text file with UnityWebRequest. When I load the file path, I get this error:

FileNotFoundException: Could not find file "D:\Unity Projects\WorkoutApp v2\UnityEngine.Networking.UnityWebRequest" Here is my code: void Awake() { UnityWebRequest workoutAssets = UnityWebRequest.Get("file://Assets/workouts.txt"); string workoutsFile = workoutAssets.ToString(); workoutList = ReadWorkouts(workoutsFile); } public List ReadWorkouts(string workoutsFile) { List fileDataList = new List(); using (StreamReader sr = new StreamReader(workoutsFile)) { string line; while ((line = sr.ReadLine()) != null) { fileDataList.Add(line); } } return fileDataList; } I'd really appreciate some guidance here!
Thank you!

Viewing all articles
Browse latest Browse all 387

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>