【问题标题】:How do I write to the internal storage file system with NativeActivity?如何使用 NativeActivity 写入内部存储文件系统?
【发布时间】:2011-09-25 10:13:20
【问题描述】:

我正在将纯 C++ 游戏移植到 Android,由于我的目标是 Android 3.0+ 平板电脑,因此我选择使用 NativeActivity 以完全避免使用 Java。但是,我看不到任何可以让我写入设备内部存储的功能。对 fopen() 的调用将失败,因为我不知道应该写入哪个目录并且内部存储文件系统不可访问

这段代码通常可以在 Java 上解决问题,为我的应用程序提供内部可写数据目录的路径:

mContext.getFilesDir();

有人知道 C++ 的替代品吗?否则我将不得不用 JNI 调用上面的 sn-p。

当然,我已经查看了 $NDK/..../include/android/ 标头,但我没有看到我需要的候选方法。

【问题讨论】:

    标签: android filesystems android-3.0-honeycomb android-ndk native-activity


    【解决方案1】:

    我终于找到了。原来内部存储目录的路径在 android/native_activity.h 中被声明为 ANativeActivity 的成员:

    /**
     * Path to this application's internal data directory.
     */
    const char* internalDataPath;
    

    【讨论】:

    • 仅供参考:显然存在一个已知错误,即 internalDataPath 和 externalDataPath 在姜饼上不起作用(始终为 NULL)。
    • 你使用的是 NativeActivity,还是旧的 Java+JNI?这些变量仅适用于纯原生应用。
    猜你喜欢
    • 2012-04-01
    • 2022-08-10
    • 2016-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-07-17
    • 2011-10-10
    • 1970-01-01
    相关资源
    最近更新 更多