Tuesday, April 4, 2017

How to browse files on Android outside of Unity app folder

So out question is : 

How to browse files on Android outside of Unity app folder?

Solution:

From Unity Documentation on this-> we can get the all knowledge about this little question:

Then now come to the point How to browse files on Android outside of Unity app folder :

From the part of the documentation:

To do this, first locate the classes.jar shipped with Unity Android. It is found in the installation folder (usually C:\Program Files\Unity\Editor\Data (on Windows) or /Applications/Unity (on Mac)) in a sub-folder called PlaybackEngines/AndroidPlayer/Variations/mono or il2cpp/Development or Release/Classes/. Then add classes.jar to the classpath used to compile the new Activity. The resulting .class file(s) should be compressed into a .jar file and placed in the Assets->Plugins->Android folder. Since the manifest dictates which activity to launch it is also necessary to create a new AndroidManifest.xml. The AndroidManifest.xml file should also be placed in the Assets->Plugins->Android folder (placing a custom manifest completely overrides the default Unity Android manifest).



If you can't do this.Then try this one->

use .net System.IO. to create a file browser, and also use Unity's AndroidJavaClass and AndroidJavaObject to call Android Native Methods like Environment.getExternalStorageDirectory to get the path to the user storage for example look the following code:

public string GetAndroidExternalStoragePath ()
          {
                  string path = "";
                  try
                  {
                      AndroidJavaClass jc = new AndroidJavaClass("android.os.Environment") ;
                      path = jc.CallStatic<AndroidJavaObject>("getExternalStorageDirectory").Call<string>("getAbsolutePath");
 return path;
                  }
                  catch (Exception e)
                  {
                    Debug.Log(e.Message);
                  }
          }



No comments:

Post a Comment