模仿 Android API Level 8 之前的 Context.getExternalFilesDir() 吗?

发布于 2024-09-24 09:39:24 字数 492 浏览 0 评论 0原文

Android API 级别 8 引入了 Context.getExternalFilesDir() 方法,提供对特定于您的应用的 SD 卡路径的 File 对象引用。我想知道如何模仿低至 API 级别 5 的功能。

我看到有一个 Context.getDir() 方法,但我无法从阅读中看出它有何不同。

Android API level 8 introduced the Context.getExternalFilesDir() method, providing a File object reference to an SD card path specific to your app. I am wondering how to mimic this as low as API level 5.

I see there is a Context.getDir() method, but I can't tell from reading about it how this differs.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

如日中天 2024-10-01 09:39:24

我最终在此处找到了答案。这是该页面的摘录,它回答了我的确切问题:

如果您使用的是 API 级别 7 或更低版本,
使用 getExternalStorageDirectory()
打开一个代表根的文件
外部存储。那么你应该
在下面写下您的数据
目录:

/Android/data//files/

是您的 Java 风格
包名,例如
com.example.android.app”。如果
用户的设备正在运行 API 级别 8
或更高,他们会卸载您的
应用程序,此目录和所有
其内容将被删除。

I ended up finding the answer here. Here's an excerpt from that page that answers my exact question:

If you're using API Level 7 or lower,
use getExternalStorageDirectory(), to
open a File representing the root of
the external storage. You should then
write your data in the following
directory:

/Android/data/<package_name>/files/

The <package_name> is your Java-style
package name, such as
"com.example.android.app". If the
user's device is running API Level 8
or greater and they uninstall your
application, this directory and all
its contents will be deleted.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文