How to access an external file in-game

Hey all,

For a project we are working on for Android, we want the user to be able to browse for files that aren’t necessarily in the app’s default save location.

I have a file browser working in-game, but I have found that it can only view and copy files from certain paths, for example I can copy/write a file from/to:

/storage/emulated/0/Android/data/com.[Comapny].[ProjectName]/files

But not from say:

/storage/emulated/0/Downloads

Which is the path I want to copy from.
I can see all the folders if I browse to /storage/emulated/0 however they appear empty even if they really have files in them.
It seems like this is a permissions issue maybe, or some limitation of the engine/Android?

My question is, is there any way I can have our app read from the downloads folder on Android?

Edit: I have just discovered that I can copy from the path “/…/…/Download” fine, so while I don’t understand exactly why it works, it is working technically…

Hi Mosel3y,

If you look in AndroidFile.cpp in PathToAndroidPaths(), there are checks for valid paths to allow:


			if ((AllowLocal && AndroidPath.StartsWith(TEXT("/"))) ||
				AndroidPath.StartsWith(GFontPathBase) ||
				AndroidPath.StartsWith(TEXT("/system/etc/")) ||
				AndroidPath.StartsWith(GExternalFilePath.Left(AndroidPath.Len())))
			{
				// Absolute paths are only local.
				LocalPath = AndroidPath;
				AssetPath = AndroidPath;
			}


Just change this to if (AllowLocal) and it should now give you access to any file path you have permission to access.

Hi Chris, just reviving an old thread after doing research on google I ran across this thread. I’m currently working on android base GearVR project and it requires me to access the SDcard of the phone to play .wav files. After seeing the new update for UE4 4.16, I saw that there’s a way to use Blueprint to gain permission access to the SDcard? I was wondering how would this work in Blueprint. thanks Chris

It depends where the .wav file is. If it is in your application’s data then you don’t need permission. If you need to access the SD Card (/mnt/sdcard for example) you’ll need READ_EXTERNAL_STORAGE permission. You can request this with the BP node. Once you have permission you can read from the directory with low-level file access (open, fopen, etc) from C++, or by using the UE4 file commands which will need the change from the quote to use absolute paths.

Hy,Chris. I was having problems with finding files on androids local drive for my File Browser, I have solved This problem by removing AllowLocal in PathToRelativePaths. I am very grateful for that. But now when i search in /mnt/sdcard/ it gives me the files in /storage/emulated/0/. I don’t know how to fix this. I think the only way I could fix this Is by asking you for your help.

Im using this code for searching files, I have found this in Ramas Victory Plugin
cpp.

#include “MyCPP_BlueprintFunctionLibrary.h”
bool UMyCPP_BlueprintFunctionLibrary::MyGetTreeAllFiles(TArray<FString>& Files, FString RootFolderFullPath, FString Ext)
{
if (RootFolderFullPath.Len() < 1) return false;

FPaths::NormalizeDirectoryName(RootFolderFullPath);

IFileManager& FileManager = IFileManager::Get();

if (Ext == "")
{
    Ext = "*.*";
}
else
{
    Ext = (Ext.Left(1) == ".") ? "*" + Ext : "*." + Ext;
}
FString FinalPath = RootFolderFullPath + "/" + Ext;
FileManager.FindFiles
(Files, *FinalPath,true, true);
return true;

}

h.

#include “CoreMinimal.h”
#include “Kismet/BlueprintFunctionLibrary.h”
#include “MyCPP_BlueprintFunctionLibrary.generated.h”
UCLASS()
class LISTCPP_API UMyCPP_BlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintPure, Category = “FileManager”)
static bool MyGetTreeAllFiles(TArray<FString>& Files, FString RootFolderFullPath, FString Ext);
UFUNCTION(BlueprintPure, Category = “FileManager”)
static bool MyDirectoryExists(FString DirectoryFullPath);
};


Hy,Chris. I was having problems with finding files on androids local drive for my File Browser, I have solved This problem by removing AllowLocal in PathToRelativePaths. I am very grateful for that. But now when i search in /mnt/sdcard/ it gives me the files in /storage/emulated/0/. I don’t know how to fix this. I think the only way I could fix this Is by asking you for your help.

Im using this code for searching files, I have found this in Ramas Victory Plugin
cpp.

#include “MyCPP_BlueprintFunctionLibrary.h”
bool UMyCPP_BlueprintFunctionLibrary::MyGetTreeAllFiles(TArray<FString>& Files, FString RootFolderFullPath, FString Ext)
{
if (RootFolderFullPath.Len() < 1) return false;

FPaths::NormalizeDirectoryName(RootFolderFullPath);

IFileManager& FileManager = IFileManager::Get();

if (Ext == "")
{
    Ext = "*.*";
}
else
{
    Ext = (Ext.Left(1) == ".") ? "*" + Ext : "*." + Ext;
}
FString FinalPath = RootFolderFullPath + "/" + Ext;
FileManager.FindFiles
(Files, *FinalPath,true, true);
return true;

}

h.

#include “CoreMinimal.h”
#include “Kismet/BlueprintFunctionLibrary.h”
#include “MyCPP_BlueprintFunctionLibrary.generated.h”
UCLASS()
class LISTCPP_API UMyCPP_BlueprintFunctionLibrary : public UBlueprintFunctionLibrary
{
GENERATED_BODY()
UFUNCTION(BlueprintPure, Category = “FileManager”)
static bool MyGetTreeAllFiles(TArray<FString>& Files, FString RootFolderFullPath, FString Ext);
UFUNCTION(BlueprintPure, Category = “FileManager”)
static bool MyDirectoryExists(FString DirectoryFullPath);
};

Hy,Chris. I was having problems with finding files on androids local drive for my File Browser, I have solved This problem by removing AllowLocal in PathToRelativePaths. I am very grateful for that. But now when i search in /mnt/sdcard/ it gives me the files in /storage/emulated/0/. I don’t know how to fix this. I think the only way I could fix this Is by asking you for your help.

It was PathToAndroidPaths, sorry for the confusion

the /mnt/sdcard path is mounted on some phones to an internal emulation of an SDCARD which is the /storage/emulated/0 you are seeing.

How can I read the file, I want the concrete and simple Example, Thank you.

Hey guys I am using webbrowser inside unreal engine. I am able to upload image from my website and also from windows but when I try to upload it from android the upload button is not responding. Can you help me out

@Mosel3y @Chris_Babcock

did you solve it ?

eventually the problem was the with file picker and that resolved our issue. You can either create ur own file picker or get it from marketplace. I bought one from marketplace.

which one did you get ? and does it work on ios too ?