gpt4 book ai didi

Android - getFilesDir() 不工作(在 Android Studio 中为红色)

转载 作者:行者123 更新时间:2023-11-30 01:30:33 28 4
gpt4 key购买 nike

我正在尝试编写一个将图像保存在磁盘上的类。

在类中我有方法 public static String saveToSdCard(Bitmap bitmap, String filename) 在里面我尝试使用 File path = new File(getFilesDir) 获取对文件夹的引用(), "myfolder");但我不能,因为 IDE 将其标记为红色。

我做错了什么?

最佳答案

你必须在上下文中调用它。确保您处于 Activity 中,或者以其他方式在上下文实例上调用它,例如 getActivity().getFilesDir()context.getFilesDir(),甚至 view.getContext().getFilesDir().

关于Android - getFilesDir() 不工作(在 Android Studio 中为红色),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35804198/

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