Hi devs,
I’m saving some files from the Application.streamingAssetsPath and copy it to the Application.persistentDataPath. Of course I do some Path.Combine() to have a better structure with folders. I use
File.WriteAllBytes(fileToDirectory, wwwStreamingFile.bytes);
to save the file and this works. I can see the folder structure at the Android device (Nexus 4), using Astro or other File Manager Apps. All folders and files are there.
Strange thing is that I can’t see the folder(s) in the windows explorer. Any idea why this can happen?
I searched a lot and tried multiple things like enable/disable “development build”, changing “Write Access” etc. Nothing worked.
I appreciate your input.
For anyone with the same problem.
My implementation of the code:
void RefreshAndroidFile(string path) //Refresh file to show up in mtp mode
{
if(!File.Exists(path))
return;
using (AndroidJavaClass jcUnityPlayer = new AndroidJavaClass ("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject joActivity = jcUnityPlayer.GetStatic<AndroidJavaObject> ("currentActivity"))
using (AndroidJavaObject joContext = joActivity.Call<AndroidJavaObject> ("getApplicationContext"))
using (AndroidJavaClass jcMediaScannerConnection = new AndroidJavaClass ("android.media.MediaScannerConnection"))
jcMediaScannerConnection.CallStatic("scanFile", joContext, new string[] { path }, null, null);
}
By calling this method after your file has been created, it should show the file and folder in Windows Explorer
string path = "/mnt/sdcard/Pictures/MyFolder/Screenshot.png"; //a path to the file
RefreshAndroidFile(path);
After some more google searching I found that it’s a known bug and also a workaround I need to implement next (second link, second reply).
-
stackoverflow.com
-
code.google.com issues
UPDATE 1: I still don’t have a working solution for this problem. Any code samples are appreciated. Thanks