Minimus Heximus
Minimus Heximus

Reputation: 2815

path for the application data in Xamarin Android

In C# Windows Forms, System.Windows.Forms.Application.LocalUserAppDataPath gives the path for the application data of a local, non-roaming user. What is its equivalent in a Xamarin Android app?

Upvotes: 1

Views: 3252

Answers (1)

SushiHangover
SushiHangover

Reputation: 74104

Xamarin.Essentials has a method called FileSystem.AppDataDirectory :

  • Android : AppDataDirectory – Returns the FilesDir of the current context
  • iOS : AppDataDirectory – Returns the Library directory
  • UWP: AppDataDirectory – Returns the LocalFolder directory

re: https://learn.microsoft.com/en-us/xamarin/essentials/file-system-helpers?context=xamarin%2Fxamarin-forms&tabs=uwp

If you do not want to use Xamarin.Essentials package, you can just use the source code for the Android implementation:

re: https://github.com/xamarin/Essentials/blob/main/Xamarin.Essentials/FileSystem/FileSystem.android.cs

Or the Xamarin.Android docs for FilesDir and using System.Environment.SpecialFolder and their Android paths within your app's sandbox:

https://learn.microsoft.com/en-us/xamarin/android/platform/files/#working-with-internal-storage

Upvotes: 1

Related Questions