简体   繁体   English

UNIX / Android低级API:需要获取“文档”路径

[英]UNIX/Android low-level API: need to get “Documents” path

I need to get the "Documents" path from C code working under Android. 我需要从在Android下工作的C代码获取“文档”路径。 The analogs for different OSs are: 不同操作系统的类似物是:

On Windows: 在Windows上:

SHGetKnownFolderIDList(FOLDERID_Documents, ...) 

returns the path to "My Documents" folder. 返回“我的文档”文件夹的路径。

On iPhone: 在iPhone上:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];

One solution is to call some Android high-level function through JNI (which function, by the way?). 一种解决方案是通过JNI调用某些Android高级功能(顺便说一下,哪个功能?)。 But is there a native function? 但是有本机功能吗?

There is no standard "Documents" path in Android. Android中没有标准的“文档”路径。

You can see the standard public directories in the DIRECTORY_* constants defined on the Environment class . 您可以Environment定义的DIRECTORY_*常量中看到标准的公共目录。 AFAIK, there is no way to get the location of those from within the NDK, other than to pass it in from Java -- you get the directory in Java from the getExternalStoragePublicDirectory() method on Environment . AFAIK,除了从Java中传递之外,没有其他方法可以从NDK中获取它们的位置-您可以从EnvironmentgetExternalStoragePublicDirectory()方法获取Java中的目录。 And none of them are "documents" -- DIRECTORY_DOWNLOADS is perhaps the closest match. 它们都不是“文档” DIRECTORY_DOWNLOADS可能是最接近的匹配项。

So, I'm going to use Android API (through a JNI call) and create the necessary folder for native data. 因此,我将使用Android API(通过JNI调用)并为本地数据创建必要的文件夹。 So, it's the function 所以这是功能

getApplication().getDir("NativeData", Context.MODE_PRIVATE).getAbsolutePath(),

that suits me. 适合我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM