I’m trying to open an image file to create a new texture2D for an AR app. Unfortunately, I’m not sure what’s going wrong here:
FString ResultFilePath = FString("");
if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
{
jstring ResultFilePathString = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, FMobileUtilsPlatform::GetImagePathMethod);
const char* nativeFilePathString = Env->GetStringUTFChars(ResultFilePathString, 0);
ResultFilePath = FString(nativeFilePathString);
Env->ReleaseStringUTFChars(ResultFilePathString, nativeFilePathString);
Env->DeleteLocalRef(ResultFilePathString);
UTexture2D* LoadedTex = NULL;
IImageWrapperModule& ImageWrapperModule = FModuleManager::LoadModuleChecked<IImageWrapperModule>(FName("ImageWrapper"));
// Need support for other image types.
IImageWrapperPtr ImageWrapper = ImageWrapperModule.CreateImageWrapper(EImageFormat::PNG);
TArray<uint8> RawFileData;
if (!FFileHelper::LoadFileToArray(RawFileData, *ResultFilePath))
{
return NULL;
}
The return value from my GetImagePathMethod looks correct, I get results that look like:
/storage/emulated/0/...
And that seems correct, but, FFileHelper always returns false. The user selects the image to be used from their gallery, so, the file certainly exists but this also returns false:
FFileHelper::FileExists(*ResultFilePath)
Is there something about File IO in android that I’m getting wrong? Or am I approaching this in C++ when I should be trying to access the file in Java?
Thanks!