android_app->活动 - > internalDataPath还是空的2.3.8 NDK R8 [英] android_app->activity->internalDataPath still NULL in 2.3.8 NDK r8

查看:366
本文介绍了android_app->活动 - > internalDataPath还是空的2.3.8 NDK R8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要给予规范在哪里我测试上,HTC Desire S,安卓2.3.5和NDK-R8。

To give spec on where i tested this, HTC Desire S, Android 2.3.5 and ndk-r8.

我有在NDK-R7B和NDK-R8访问使用android_app->活动 - > internalDataPath或externalDataPath,因为它们都是空的地方读写的目录问题。我看到,这已经张贴在previous版本和更新打算为此,根据这个帖子来解决: -

I am having issues in ndk-r7b and in ndk-r8 accessing the local read write directories using android_app->activity->internalDataPath or externalDataPath as they are both NULL. I see that this has been posted in previous versions and an update was going to fix this according to this post:-

<一个href="http://stackoverflow.com/questions/6525724/how-do-i-write-to-the-internal-storage-file-system-with-nativeactivity">How我写与NativeActivity的内部存储文件系统?

现在或许这被固定在冰淇淋三明治但这远非理想,因为我的工具链支持向后兼容性完全赶上那些谁不更新。所以我的问题是有没有一个已知的固定或我必须手动添加,如/data/data/com.example.mytest/files/somefile.dat的目录结构,直到它固定的吗?

Now perhaps this gets fixed in Ice Cream Sandwich but that's far from ideal as my tool chain supports backwards compatibility perfectly to catch those who don't update. So my question is is there a known fix or do i have to manually add the directory structure like "/data/data/com.example.mytest/files/somefile.dat" untill its fixed ?

推荐答案

从NDK下工作而不使用Java:

The following works from NDK without use of Java:

const char* path = app->activity->internalDataPath;
if (!path) {
    JNIEnv* jni;
    app->activity->vm->AttachCurrentThread(&jni, NULL);

    jclass activityClass = jni->GetObjectClass(app->activity->clazz);
    jmethodID getFilesDir = jni->GetMethodID(activityClass, "getFilesDir", "()Ljava/io/File;");
    jobject fileObject = jni->CallObjectMethod(app->activity->clazz, getFilesDir);
    jclass fileClass = jni->GetObjectClass(fileObject);
    jmethodID getAbsolutePath = jni->GetMethodID(fileClass, "getAbsolutePath", "()Ljava/lang/String;");
    jobject pathObject = jni->CallObjectMethod(fileObject, getAbsolutePath);
    path = jni->GetStringUTFChars((jstring)pathObject, NULL);

    jni->DeleteLocalRef(pathObject);
    jni->DeleteLocalRef(fileClass);
    jni->DeleteLocalRef(fileObject);
    jni->DeleteLocalRef(activityClass);

    app->activity->vm->DetachCurrentThread();
}

这篇关于android_app-&GT;活动 - &GT; internalDataPath还是空的2.3.8 NDK R8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆