Quantcast
Channel: Recent Threads — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 204402

Raw Resource file access

$
0
0

In MonoTouch I'm reading files from my resources (res) directory using the following example:

string gameData = File.ReadAllText ("./res/game.dat");

I was horrified to learn today that I can't do the same thing in Android and I'm gonna have to rewrite how my core codebase works, which was built around using a helper method to get a platform specific path.

I've done lots of searching and seen Android solutions involving a 'raw' directory in the Resources, but the following code doesn't work. When getting the AbsolutePath from the uri only the '/raw/game.dat' part is returned.

Uri uri = new Uri ("android.resource://androidTest.androidTest/raw/game.dat");

string gameData = File.ReadAllText (uri.AbsolutePath);

Done anyone have any experience with this?

I'm not keen on rewriting my codebase where iOS returns file data based on file paths and Android works with ids with a filestream. I should be able to simply provide a filename to my helper, that prefixes the platform specific directory to it, and I read the contents using .net IO classes.

Thanks,

Dan


Viewing all articles
Browse latest Browse all 204402

Trending Articles



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