Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 747
lysergic-acid Avatar asked Jul 14 '26 14:07

lysergic-acid


1 Answers

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.

like image 84
eozgonul Avatar answered Jul 18 '26 07:07

eozgonul