1#if UNITY_ANDROID && !UNITY_EDITOR
3using System.Collections;
4using System.Collections.Generic;
10 public class StandaloneFileBrowserAndroidListener : AndroidJavaProxy
12 private Action<IList<ItemWithStream>> _multipleFilesCallback;
14 public StandaloneFileBrowserAndroidListener(Action<IList<ItemWithStream>> onMultipleFilesSelected) : base(
"com.sfb.standalonefilebrowser.StandaloneFileBrowserAndroidListener")
16 _multipleFilesCallback = onMultipleFilesSelected;
19 public void onFilesSelected(
string filenames)
21 if (_multipleFilesCallback !=
null) {
22 var files = filenames.Split(
'|');
23 var itemsWithStream =
new ItemWithStream[files.Length];
24 for (var i = 0; i < itemsWithStream.Length; i++) {
25 itemsWithStream[i] =
new ItemWithStream() {
29 _multipleFilesCallback(itemsWithStream);
34 public class StandaloneFileBrowserAndroid : IStandaloneFileBrowser<ItemWithStream>
36 private AndroidJavaClass _standaloneFileBrowser;
37 private AndroidJavaObject _activity;
39 public StandaloneFileBrowserAndroid()
41 using (AndroidJavaObject unityClass =
new AndroidJavaClass(
"com.unity3d.player.UnityPlayer"))
43 _activity = unityClass.GetStatic<AndroidJavaObject>(
"currentActivity");
44 _standaloneFileBrowser =
new AndroidJavaClass(
"com.sfb.standalonefilebrowser.StandaloneFileBrowser");
48 public IList<ItemWithStream> OpenFilePanel(
string title,
string directory, ExtensionFilter[] extensions,
bool multiselect)
50 throw new NotSupportedException();
53 public void OpenFilePanelAsync(
string title,
string directory, ExtensionFilter[] extensions,
bool multiselect, Action<IList<ItemWithStream>> cb)
55 var listener =
new StandaloneFileBrowserAndroidListener(cb);
56 var args =
new object[] {_activity, title, multiselect, listener};
57 _standaloneFileBrowser.CallStatic(
"showOpenFileDialog", args);
60 public IList<ItemWithStream> OpenFolderPanel(
string title,
string directory,
bool multiselect)
62 throw new NotSupportedException();
65 public void OpenFolderPanelAsync(
string title,
string directory,
bool multiselect, Action<IList<ItemWithStream>> cb)
67 throw new NotSupportedException();
70 public ItemWithStream SaveFilePanel(
string title,
string directory,
string defaultName, ExtensionFilter[] extensions)
72 throw new NotSupportedException();
75 public void SaveFilePanelAsync(
string title,
string directory,
string defaultName, ExtensionFilter[] extensions, Action<ItemWithStream> cb)
77 throw new NotSupportedException();