简体   繁体   中英

accessing application data path from NDK code

I'm building c++ code for Android using NDK. My code will be used as an external SDK for app developers.

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).

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.

/**
* 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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