Pav*_* S. 8 android shared-libraries android-ndk android-assets
在我的应用程序中,我必须将一个文件从assets文件夹传递到共享库.我现在不能使用jni.我在我的项目中使用预编译的共享库,其中我有我的文件的硬编码路径,但我收到错误"没有这样的文件或目录".所以在我的.apk文件中,我在libs/armeabi-v7a文件夹中有.so文件,在/ assets文件夹中有我的文件.
我试过这样做:
char *cert_file = "/assets/cacert.cert";
av_strdup(cert_file);
Run Code Online (Sandbox Code Playgroud)
和其他一些路径,但它不起作用.
有可能吗?
Sis*_*str 15
您只需在C++中使用AAssetManager类即可.
基本上你需要:
AAssetManager* assetManager用它来读取你的文件:
// Open your file
AAsset* file = AAssetManager_open(assetManager, filePath, AASSET_MODE_BUFFER);
// Get the file length
size_t fileLength = AAsset_getLength(file);
// Allocate memory to read your file
char* fileContent = new char[fileLength+1];
// Read your file
AAsset_read(file, fileContent, fileLength);
// For safety you can add a 0 terminating character at the end of your file ...
fileContent[fileLength] = '\0';
// Do whatever you want with the content of the file
// Free the memoery you allocated earlier
delete [] fileContent;
Run Code Online (Sandbox Code Playgroud)编辑:获取AAssetManager对象:
- 在本机活动中,你主要作为一个参数android_app*app,你只需要在这里得到它:app-> activity-> assetManager
- 如果您有Java活动,则需要通过JNI发送java对象AssetManager的实例,然后使用函数AAssetManager_fromJava()
| 归档时间: |
|
| 查看次数: |
6824 次 |
| 最近记录: |