- Home /
Access files in apk
Hi All,
I am a novice into unity and i need to access files to load a different scene file within an apk.
I have got the directory in an apk by adding those files in StreamingAssets folder and can see files within the apk bundle when i extract it .
I am trying to access the file like below:
public static string[] getAllGames() { string[] gamefiles;
string Path = "jar:file://" + Application.dataPath + "!/assets/";
WWW wwwfile = new WWW(Path);
while (!wwwfile.isDone) { }
var filepath = string.Format("{0}/{1}", Application.persistentDataPath, "");
File.WriteAllBytes(filepath, wwwfile.bytes);
gamefiles = System.IO.Directory.GetDirectories(filepath + "/");
for (int i = 0; i < gamefiles.Length; i++)
{
gamefiles[i] = gamefiles[i].Replace(path + "/", "");
}
return gamefiles;
nothing happens in the app , Please let me know what i am doing wrong here
Are you trying to access a .unity scene file from the same program .apk as you have installed and are running your code from? Or do you download a different .apk and want to access files in it?
For the first one you can place myfile.txt in for example Project folder then "/Assets/Resources/Levels/myfile.txt", then you can access the file like this
string szFilenameNoExt = "myfile"; //notice no .txt extension
TextAsset f = (TextAsset)Resources.Load("Levels/" + szFilenameNoExt);
byte[]bytes = f.bytes;
But it's hard to know what you are trying to do, because the code you have showed us is broken.
Answer by sahnik1 · Mar 17 at 08:57 PM
@rh_galaxy Thanks for your response
My GUI Menu looks like the image attached below:
On Clicking at File >Load I am trying to show directories available to load,I am able to add those directory from resources folder to StreamingAssets hence see them in apk . In the code posted above i am trying to get directories within the apk path as they are present there and return the same.
Once i am in that game my purpose will be to load different scenes there by clicking on Scene>Load but i hope code for it will be written the same way, which i am struggling currently.
Your answer
Follow this Question
Related Questions
UI Input fields not working properly in Unity 5 on Android 1 Answer
Different animations on mobile 0 Answers
Time.realtimeSinceStartup returns negative number 3 Answers
Unable to Create or Sign APK File for Android 3 Answers
2d android game sensor 1 Answer