2017-04-10 61 views
0

我使用Xamarin開發我的應用程序。我看到很多答案,但沒有找到可以幫助我的東西。我如何獲得位於sdcard0中的應用程序文件夾的路徑?我想得到這樣的東西:/storage/sdcard0/Android/data/[MyApplication]/files如何獲取位於sdcard0中的應用程序文件夾的路徑?

我做了以下內容:

var path = Environment.GetFolderPath(Environment.SpecialFolder.Personal); 

它給了我"/data/data/App1.Droid/files"但它不是我要找的。

+0

我正在使用Android Studio,也許你可以試試'Environme nt.getExternalStorageDirectory()。getAbsolutePath()' –

+0

使用'getCanonicalPath()'。看到[這](http://stackoverflow.com/questions/11488754/whats-the-difference-between-canonicalpath-and-absolutepath)acc評論我的回答! ; D –

回答

1
// this for your application directory 
System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal) 



// for external storage 
File path = Android.OS.Environment.getExternalStoragePublicDirectory(
      Environment.DIRECTORY_PICTURES); 

Reference

更新

注:調用System.Environment =>您需要在機器人的應用程序不能使用PCL

被稱爲調用Android.OS.Environment =>您需要引用單.android在你的PCl或直接在你的機器人應用程序中調用

+0

我使用Xamarin框架和C#語言。不幸的是,沒有API提供你的方法。你可以看到這個鏈接https://developer.xamarin.com/api/type/Android.OS.Environment/這部分代碼是'Android.OS.Environment.GetExternalStoragePublicDirectory(「files」);''給我''/ storage/sdcard0/files「,但我還需要我的應用程序文件夾。 –

+1

如果你在你的droid應用程序中調用這個方法,它會工作得很好,但是如果你在PCl中調用(首先你不能調用System.Environment,其次你需要引用單聲道android來調用Android.OS.Environment) –

相關問題