.NET for Androidの特殊ディレクトリのパス

.NET for AndroidではXamarin.Androidの頃から微妙に値が変わっています。

環境
  • .NET 8 for Android (net8.0-android)

.NET 8での結果です。.NET 6や.NET 7は試していません。

SpecialFolder .NET 8 for Android (net8.0-android) 備考
Desktop /data/user/0/{パッケージ名}/files/Desktop
Programs
MyDocuments /data/user/0/{パッケージ名}/files/Documents
MyDocuments /data/user/0/{パッケージ名}/files/Documents
Favorites
Startup
Recent
SendTo
StartMenu
MyMusic /data/user/0/{パッケージ名}/files/Music
MyVideos /data/user/0/{パッケージ名}/files/Videos
DesktopDirectory /data/user/0/{パッケージ名}/files/Desktop
MyComputer
NetworkShortcuts
Fonts /data/user/0/{パッケージ}/files/.fonts
Templates /data/user/0/{パッケージ名}/files/Templates
CommonStartMenu
CommonPrograms
CommonStartup
CommonDesktopDirectory
ApplicationData /data/user/0/{パッケージ名}/files/.config
PrinterShortcuts
LocalApplicationData /data/user/0/{パッケージ名}/files 一番使うと思う
InternetCache
Cookies
History
CommonApplicationData /usr/share
Windows
System
ProgramFiles
MyPictures /data/user/0/{パッケージ名}/files/Pictures
UserProfile /data/user/0/{パッケージ名}/files
SystemX86
ProgramFilesX86
CommonProgramFiles
CommonProgramFilesX86
CommonTemplates /usr/share/templates
CommonDocuments
CommonAdminTools
AdminTools
CommonMusic
CommonPictures
CommonVideos
Resources
LocalizedResources
CommonOemLinks
CDBurning


参考コード 編集

AndroidではSystem.EnvironmentとAndroid.OS.Environmentの名前がぶつかるのでフルネームで指定した方がいい。

foreach (var folder in Enum.GetValues(typeof(System.Environment.SpecialFolder)))
{
    var path = System.Environment.GetFolderPath((System.Environment.SpecialFolder)folder);
    Console.WriteLine($"{folder} => {path}");
}