我实际上能够通过荷兰广播公司打电话getPackageCodePath
,并能够工作。 The following Code set at the first of android_main
in the home-active model in NDK r7logs the right path and don tock:
void android_main(struct android_app* state) {
struct engine engine;
ANativeActivity* activity = state->activity;
JNIEnv* env = activity->env;
jclass clazz = (*env)->GetObjectClass(env, activity->clazz);
jmethodID methodID = (*env)->GetMethodID(env, clazz, "getPackageCodePath", "()Ljava/lang/String;");
jobject result = (*env)->CallObjectMethod(env, activity->clazz, methodID);
const char* str;
jboolean isCopy;
str = (*env)->GetStringUTFChars(env, (jstring)result, &isCopy);
LOGI("Looked up package code path: %s", str);
...
}
但我觉得这样可能不是一个伟大的解决办法。 对我有两点担忧:
- Thread safety - there s an ugly warning about only using the
env
member of ANativeActivity
in the main Java thread, and if I understand things correctly, this code is going to get run in the native activity s thread.
ANativeActivity
s clazz
member appears to be misnamed and is actually the instance of the Java NativeActivity
instead of the class object. Otherwise this code wouldn t work. I really hate relying on something that is obviously misnamed like this.
除此之外,它还发挥作用,而且我实际上打算利用它自己,利用校准和数据目录将资产从原木中提取。