It look like the problem is with the type of my project. My project is Android XAML App (Xamarin Forms). The namespace Android.OS is only available in projects Android App (Xamarin). Is there a way to resolve that?
You could create a dependency service
to obtain it on Forms.
Xamarin.Forms DependencyService Introduction:
https://learn.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/dependency-service/introduction
Create the interface:
public interface IDpendencyService
{
string GetExternalStorage();
}
The implementation on the Android project could be like this:
public class DependencyImplementation : IDpendencyService
{
public string GetExternalStorage()
{
var path = Android.OS.Environment.ExternalStorageDirectory.ToString();
return path;
}
}
Do not forget to register in MainActivity.cs:
Xamarin.Forms.DependencyService.Register<IDpendencyService, DependencyImplementation>();
Usage in Xamarin.forms:
private void Button_Clicked(object sender, EventArgs e)
{
var path = DependencyService.Get<IDpendencyService>().GetExternalStorage();
}