gpt4 book ai didi

c# - Context.GetExternalFilesDir() 不接受 null

转载 作者:行者123 更新时间:2023-12-04 03:47:47 25 4
gpt4 key购买 nike

我正在尝试获取我的 c# xamarin android 应用程序的私有(private)外部存储目录的路径。微软文档告诉我们使用

Android.Content.Context.GetExternalFilesDir(string)

但是,当我尝试使用这个函数时,我收到关于该函数的以下错误:

An object reference is required for the non-static field, method or property

这是我的代码

class RecorderController {
string externalStoragePath;

public RecorderController() {
externalStoragePath = Path.Combine(Context.GetExternalFilesDir(null), "recordings");

// I have also tried the following:
// string s = null;
// externalStoragePath = Path.Combine(Context.GetExternalFilesDir(s), "recordings");

// Even when I try to get the path to the Downloads folder, I get the same error:
// string s = Android.OS.Environment.DirectoryDownloads;
// externalStoragePath = Path.Combine(Context.GetExternalFilesDir(s), "recordings");
}
}

我不知道如何解决这个问题,有人知道我做错了什么吗?

最佳答案

努力改变

externalStoragePath = Path.Combine(Context.GetExternalFilesDir(null), "recordings");

externalStoragePath = Path.Combine(GetExternalFilesDir(null).AbsolutePath, "recordings");

关于c# - Context.GetExternalFilesDir() 不接受 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64885237/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com