Question

I wanted to use Android Assets and followed the tutorial in the official docs.

Have set the asset type to AndroidAssets like it says, but it was throwing exceptions for not finding the file. I have a rooted device so upon inspection I noticed that the files are not actually on the device at all (/data/data/com.company.application/files/SomeFile.txt).

EDIT:

String filename = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "AboutAssets.txt");
FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read);
Was it helpful?

Solution 2

Posted this a while ago and ended up not using Xamarin because I never found a solution. I have recently come back to Xamarin and the latest updates seem to have fixed this issue - the same project now works fine with no changes made.

So if anyone else encounters this - try updating.

OTHER TIPS

You can try:

AssetManager assets = context.getAssets();
InputStream is = assets.open(filename);

The context Object refer to the Context of Application.

Android Assets are stored in the APK file, so you can't find the file using your code. There is no absolute path to those files.

Just use Assets.Open to access assets, exactly like what taught in the tutorial.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top