Question

I have an object creation in my native part of an Android application like this:

CascadeClassifier face_cascade;
face_cascade.load( "haarcascades/haarcascade_frontalface_alt2.xml" );

In pure c++ you place haarcascade_frontalface_alt2.xml in haarcascades folder besides your sources. But now I'm really confused where it should be placed ? In jni/haarcascades directory ? Or somewhere else?
Thanks in advance.

Was it helpful?

Solution

Android application starts with the filesystem root as current directory. Also, when you deploy an Android app, you normally put the files either in res/raw directory, or in assets directory of your Java project. You can access assets directly form native code (see http://www.costrategix.com/blog/reading-files-from-android-assets-folder-using-c-ndk/ and AssetManager and native code).

Android isolates file access for different apps, so that each can store its private files. Android apps often use the /sdcard/ for file storage because there is usually much more space there. Also, it's easier for the native code to find the files on the sdcard. But be careful: /sdcard/ may not be present on some devices under some circumstances. Often, Android system will have an environment variable EXTERNAL_STORAGE which may be used instead; but the official supported way to find this path is through Java API.

It is impossible to manipulate the current directory from Java, but you can use JNI for that.

Anyways, the native code has the same file access permissions as the Java code.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top