skzi
skzi

Reputation: 373

Xamarin - Read Assets from Shared Project

I am using Xamarin for Android / iOS development. I have added a Shared Project within Xamarin solution. One of the functionality in the Shared project would be read assets within Android. However, AssetManager or Assets is not available from the Shared project. Any clue on how this can be used?

Upvotes: 2

Views: 977

Answers (1)

Juergen
Juergen

Reputation: 23

Maybe a bit late - hope it still helps somebody. You can use https://github.com/juergenkoller/PCLStorage

It has a GetFileFromAppBundleAsync function. You can place your file inside the asset folder of your Android project and do something like this:

var file = await FileSystem.Current.GetFileFromAppBundleAsync("your file.xyz", new CancellationToken(false));
var content = await file.ReadAllTextAsync ();

Upvotes: 1

Related Questions