- Home /
Question by
renezuidhof · Mar 07, 2015 at 09:53 PM ·
not showing
Storing files on Android not showing up on Windows
In my app i generate some .wav files. They are stored on the sdcard (PersistentPath + external write = true). I can see it with Eclipse but they are not showing up on Windows via USB.
With native Android you can use the code below to show files, is there a Unity method to do this?
MediaScannerConnection.scanFile(this, new String[] {path.toString()}, null, null);
Comment
Answer by Monsieur_AirHead · Mar 06, 2016 at 08:06 PM
This can be done from unity using the following code in Unity, source. In this example file_path is a string indicating the location of your *.wav file.
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"))
using (AndroidJavaClass jcEnvironment = new AndroidJavaClass ("android.os.Environment"))
using (AndroidJavaObject joExDir = jcEnvironment.CallStatic<AndroidJavaObject> ("getExternalStorageDirectory")) {
string path = joExDir.Call<string> ("toString") + file_path;
jcMediaScannerConnection.CallStatic ("scanFile", joContext, new string[] { path }, null, null);
}
Your answer
Follow this Question
Related Questions
GUI Rect not showing on play 2 Answers
Terrain grass does not show up on runtime 1 Answer
UI Canvas only showing up on server. 1 Answer
One of my assets is not showing up 1 Answer