简体   繁体   English

从NDK代码访问应用程序数据路径

[英]accessing application data path from NDK code

I'm building c++ code for Android using NDK. 我正在使用NDK为Android构建c ++代码。 My code will be used as an external SDK for app developers. 我的代码将用作应用程序开发人员的外部SDK。

Is it possible to access the application's data path from the native code? 是否可以从本机代码访问应用程序的数据路径?

One option is to use JNI to call into the JVM and look up this information, however since i am writing library code, i am not sure my SDK won't be used in an all native applicaiton (NativeActivity). 一种选择是使用JNI调用JVM并查找此信息,但是由于我正在编写库代码,因此我不确定我的SDK是否将不会用于所有本机应用程序(NativeActivity)。

What is the best option for achieving this? 实现这一目标的最佳选择是什么?

It is possible to access application's data path from the full native code. 可以从完整的本机代码访问应用程序的数据路径。 External and internal storage paths are stored inside android_app->activity, which is of type ANativeActivity and android_app struct is defined at the entry point of the native activity, so you don't have to worry about anything. 外部和内部存储路径存储在android_app-> activity中,其类型为ANativeActivity,android_app结构是在本机活动的入口点定义的,因此您不必担心任何事情。

/**
* Path to this application's internal data directory.
*/
const char* internalDataPath;

/**
 * Path to this application's external (removable/mountable) data directory.
 */
const char* externalDataPath;

In case there is no native activity, storage paths can be queried through JNI as it is stated in the comments. 如果没有本机活动,可以通过JNI查询存储路径,如注释中所述。

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

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