gpt4 book ai didi

java - 以编程方式启用存储 android

转载 作者:行者123 更新时间:2023-12-01 09:24:39 24 4
gpt4 key购买 nike

我正在尝试使用 C++ Android NDK 遍历 SD 卡中的文件,只是为了让用户在他的设备中选择一个文件,我使用 dirent.h header ,并从中获取 SD 路径java 方法 Environment.getExternalStorageDirectory()

当我在具有 Android 4.4.2 的 BlueStacks(在 Windows 10 上)上测试它时,该函数可以正确读取文件名,但是当我在具有 Android 7 的 Nexus 6p 上测试它时,它会失败,并给出 errno = 13,这意味着:

#define EACCES      13  /* Permission denied */

在下面的帖子中,我可以找到发生这种情况的原因。

https://stackoverflow.com/a/36336679/5166295

那么,是否有任何以编程方式启用该选项的方法?

只有在我调试应用程序时才会出现这种情况,并且在最终版本(带有 APK)中这种情况会消失吗?

或者,有什么方法可以获取原始路径而不是符号链接(symbolic link)吗?

或者,我是否必须告诉我的用户手动启用该选项?

最佳答案

I get the SD path from java with the method Environment.getExternalStorageDirectory()

getExternalStorageDirectory() 与约 20 亿 Android 设备上的 SD 卡无关。这指向 external storage ,不是removable storage .

Is there any programmatically way to enable that option?

您的 Java 代码可以 request READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE at runtime 。我不认为有办法直接从 NDK 请求这个。

Is this only while I'm debugging the app, and in the final version (with the APK) this will dissapear?

没有。

关于java - 以编程方式启用存储 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39936931/

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