Referencing external images android

We have unity for iphone and android.
with unity iphone we are puting images into a folder called DATA and loading them at runtime.
It isnt working with our android build and we were wondering if there was a different directory to put our files in to reference them.

Thanks,
Chris

How do you “put” images into this DATA folder? And where is the DATA folder?

Hmmm… Sorry for being vague. The Data folder is something that xcode uses. We are putting jpgs in there and referencing them in. WE are new to building for android and my dev wants to open the apk file and put the jpgs in there so he can reference them like we can do with our ios unity build. Does that mkae sense?

Thanks.
Chris

If I understand you I think you’ll want to look into this;
http://forum.unity3d.com/threads/71607-Integrating-Unity-and-Eclipse

After following that you should be able to add the jpgs in Eclipse and build from there. Much like you do with xcode.

Hey there,
My developer has spent over 7 full days trying every solution possible to load external JPGS on the android device.
None of the methods we have tried have worked. If anyone can think of a solution I will hire them to do this.
Thanks,
Chris

WWW tex = new WWW(“url to jpg”);
yield tex;
Texture2D texture = tex.texture;

should work afaict…

Ok. It seems that the problem is getting the jpg in the build. Our developer has tried many methods and still hasnt been able to do it. Does anyone have a suggestion for this?

I see 3 options:

  1. put the image in the StreamingAssets folder
  2. put the image under Plugins/Android/assets/
  3. use the Eclipse scheme linked to in an earlier post.

In all three cases the file will show up under /assets inside the .apk and can be loaded from “jar:file://” + Application.dataPath + “!/assets/<file_name>”.

So, I am having the same issue loading files from StreamingAssets. Unzipping the .apk shows that the files are definitely in the assets folder. When I go to load them using a StreamReader using the path below I get the exception below:

File Path:

jsonConfigFile = "jar:file://" + Application.dataPath + "!/assets/" + filename;

Exception:

IsolatedStorageException: Could not find a part of the path "/jar:file:/data/app/com.prime31.UITest-2.apk!/assets/file.json"

What is the proper path for loading a file in the /assets folder of an apk?

Edit: I think I have tried every permutation of path that I can think of and in no case is the file accessible with a StreamReader.

just put your image files in:
*Assets\Plugins\Android\res\drawable*

I’ll give it a shot but it sure does ruin the cross platform goodness that StreamingAssets provides. Is there really no way to get at the contents of the assets folder without resorting to a plugin?

Yes, that’s because you need to use WWW() to access the data. Remember that the files you are trying to access are sitting inside the .apk and are not accessible as plain files.

That only makes sense if the files are a) images, and b) accessed from Java code.
Prime31 is trying to load .json files, and those are not supported in res/drawable.

Copying your files to the StreamingAssets folder will have the exact same effect as putting the files under Assets/Plugins/Android/assets, except that files under StreamingAssets are never compressed (inside the .apk).
You can access these files through the WWW(“jar:file://…”) interface described earlier. Or through a plugin / Java code.

Yeah, I guess I was hoping Unity took care of creating an AssetManager and reading in the InputStream by way of magic. I’ve switched gears and stopped using StreamingAssets for cross platform stuff. As a feature request it would be nice if there was a way out of the box to read in a file from StreamingAssets to keep parity with the other platforms.

why not put them on the resource folder on unity and load them from there?

That’s exactly what I ended up doing. I just felt more comfortable with memory management being able to wrap a StreamReader in a using block and reading it line by line. The TextAsset path will work fine though.