gpt4 book ai didi

android - 在 API 23 及更高版本中插入 SD 卡后,getExternalFilesDirs() 未在 ApplicationContext 中更新

转载 作者:太空狗 更新时间:2023-10-29 14:46:06 24 4
gpt4 key购买 nike

当应用程序在前台运行并插入SD卡时,尝试通过使用检索路径

ctx.getExternalFilesDirs(Environment.DIRECTORY_DOWNLOADS);

上下文有时是ApplicationActivity上下文

使用 Activity 上下文时,获取更新的 SD 卡路径,但使用应用程序上下文时,不获取更新的路径

它只发生在 API 2324

Workaround is to kill the app and re-start the app

有人知道这是 Marshmallow 的错误吗?

注意:我看到一些在 google 中创建了一个问题 Issue 214247

最佳答案

使用 Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)Environment.getExternalStorageState()

类型 DIRECTORY_DOWNLOAD 未列为 getExternalFilesDir() 的有效参数,请查看文档:https://developer.android.com/reference/android/content/Context.html#getExternalFilesDir(java.lang.String)

关于android - 在 API 23 及更高版本中插入 SD 卡后,getExternalFilesDirs() 未在 ApplicationContext 中更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40120227/

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