In Xamarin.Android project, Assets
are read using an AssetManager
. An instance of the AssetManager
is available by accessing the Assets property on an Android.Content.Context
, such as an Activity.
For example:
string content;
AssetManager assets = this.Assets;
using (StreamReader sr = new StreamReader (assets.Open ("zimbabwe.shp")))
{
content = sr.ReadToEnd ();
}
And in Xamarin.Forms project,you could also add any file into the Assets
folder in the Android project and mark the Build Action
as AndroidAsset
to use it with OpenAppPackageFileAsync
.
using (var stream = await FileSystem.OpenAppPackageFileAsync(templateFileName))
{
using (var reader = new StreamReader(stream))
{
var fileContents = await reader.ReadToEndAsync();
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…