android+读取png,android 读取文件路径跟数据,(png,openal soft)

66b52468c121889b900d4956032f1009.png

8种机械键盘轴体对比

本人程序员,要买一个写代码的键盘,请问红轴和茶轴怎么选?

摘要:android 读取文件路径跟数据,(png,openal soft)

参考

http://stackoverflow.com/questions/11294487/android-writing-saving-files-from-native-code-only

void android_main(struct android_app* state)

{

// Make sure glue isn't stripped

app_dummy();

ANativeActivity* nativeActivity = state->activity;

const char* internalPath = nativeActivity->internalDataPath;

std::string dataPath(internalPath);

// internalDataPath points directly to the files/ directory

std::string configFile = dataPath + "/app_config.xml";

// sometimes if this is the first time we run the app

// then we need to create the internal storage "files" directory

struct stat sb;

int32_t res = stat(dataPath.c_str(), &sb);

if (0 == res && sb.st_mode & S_IFDIR)

{

LOGD("'files/' dir already in app's internal data storage.");

}

else if (ENOENT == errno)

{

res = mkdir(dataPath.c_str(), 0770);

}

if (0 == res)

{

// test to see if the config file is already present

res = stat(configFile.c_str(), &sb);

if (0 == res && sb.st_mode & S_IFREG)

{

LOGI("Application config file already present");

}

else

{

LOGI("Application config file does not exist. Creating it ...");

// read our application config file from the assets inside the apk

// save the config file contents in the application's internal storage

LOGD("Reading config file using the asset manager.n");

AAssetManager* assetManager = nativeActivity->assetManager;

AAsset* configFileAsset = AAssetManager_open(assetManager, "app_config.xml", AASSET_MODE_BUFFER);

const void* configData = AAsset_getBuffer(configFileAsset);

const off_t configLen = AAsset_getLength(configFileAsset);

FILE* appConfigFile = std::fopen(configFile.c_str(), "w+");

if (NULL == appConfigFile)

{

LOGE("Could not create app configuration file.n");

}

else

{

LOGI("App config file created successfully. Writing config data ...n");

res = std::fwrite(configData, sizeof(char), configLen, appConfigFile);

if (configLen != res)

{

LOGE("Error generating app configuration file.n");

}

}

std::fclose(appConfigFile);

AAsset_close(configFileAsset);

}

}

}

取得AAsetManager之后就好办了

读取png的话就用loadpng

声音的话就openAL soft

android_app*g_pAndroid_App = 0;

void AndroidInit(android_app*e_pAndroid_App)

{

g_pAndroid_App = e_pAndroid_App;

}

std::string AndroidGetPath(const char*e_strFileName)

{

ANativeActivity* nativeActivity = g_pAndroid_App->activity;

const char* internalPath = nativeActivity->internalDataPath;

std::string dataPath(internalPath);

// internalDataPath points directly to the files/ directory

std::string configFile = dataPath;

configFile += e_strFileName;

return configFile;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值