Saved folders (Application.persistentDataPath) showing on Android device but not in windows explorer
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.
Ok, I got another Android phone (Samsung S3) and tested it. It works on this device. When I do my copying and after a reconnection of the USB cable the folders are visible in the windows explorer. All looks good as expected.
Now the question still remains why it's not showing on the Nexus 4. I'll google for a while and see if I can find an answer for the issue.
I want the files/data be accessible by the end users, so they need to find the files on their device (best case when connected to a PC).
iOS will be another question I guess. Never looked into it if it is possible to get access to saved files.
Answer by djiango · Apr 06, 2017 at 12:26 PM
For anyone with the same problem.
http://answers.unity3d.com/questions/918210/storing-files-on-android-not-showing-up-on-windows.html
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);
Answer by Railon23 · Sep 01, 2015 at 04:29 PM
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).
UPDATE 1: I still don't have a working solution for this problem. Any code samples are appreciated. Thanks
Your answer
Follow this Question
Related Questions
Android PersistentDataPath UnauthorizedAccessException 0 Answers
Reading in from a text file (.txt) when deploying to Android devices. 0 Answers
Open Location of Application.persistentDataPath android 0 Answers
transfer data between android to Window throught a USB cable 0 Answers
Android Size Different [S5] [TAB A] 1 Answer