【问题标题】:How to get path to the application's files folder which is situated in sdcard0?如何获取位于 sdcard0 中的应用程序文件夹的路径?
【发布时间】:2017-04-10 09:42:40
【问题描述】:

我正在使用 Xamarin 开发我的应用程序。我看到了很多答案,但没有找到可以帮助我的东西。如何获取位于 sdcard0 中的应用程序文件夹的路径?我想得到类似的东西:/storage/sdcard0/Android/data/[MyApplication]/files

我做了以下事情:

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

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

【问题讨论】:

  • 我用的是Android Studio,你可以试试Environment.getExternalStorageDirectory().getAbsolutePath()
  • 使用getCanonicalPath()。请参阅this 接受我的评论作为答案! ;D

标签: c# android xamarin


【解决方案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 => 你需要在 droid 应用程序中不能在 PCl 中调用

要调用Android.OS.Environment => 你需要在你的 PCl 中引用 mono.android 或者在你的 droid 应用程序中直接调用

【讨论】:

  • 我使用 Xamarin 框架和 C# 语言。不幸的是,没有提供您方法的 API。你可以看到这个链接developer.xamarin.com/api/type/Android.OS.Environment这部分代码Android.OS.Environment.GetExternalStoragePublicDirectory("files");给了我"/storage/sdcard0/files",但我也需要我的应用程序文件夹。
  • 如果你在你的 droid 应用程序中调用这个方法,它会工作得很好,但是如果你在 PCl 中调用(首先你不能调用 System.Environment,其次你需要参考 mono android 来调用 Android.OS。环境)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-06-21
  • 2019-06-24
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多