Keiwando.NFSO.NativeFileSO
instance method
OpenFile
public void OpenFile (SupportedFileType[] supportedTypes, Action<bool, OpenedFile> onCompletion)
Summary
Presents a native dialog to the user which allows them to select a
single file to be opened. The selected file contents are then loaded
into memory managed by an instance of the OpenedFile
class.
Parameters
supportedTypes
onCompletion
Examples
The following example demonstrates how to prompt the user to select a file to be opened and then handle the results of that operation accordingly.
// Determine which file types the user can choose from.
SupportedFileType[] fileTypes = {
SupportedFileType.PlainText
};
OpenFile(fileTypes, delegate(bool fileWasOpened, OpenedFile file) {
if (fileWasOpened) {
// Process the loaded file contents, e.g. using
// OpenedFile.ToUTF8String()
.
} else {
// The file selection was cancelled.
}
});
Remarks
The supportedTypes
array is just an indicator to the native file chooser
dialog to only allow the user to choose from files of predefined types.
However, this is not a guarantee that the chosen file is going to contain
data in the correct file format.
For one, the file chooser on Android allows the user to circumvent the file type filter and ultimately select an arbitrary file. At the same time, the file choosers that rely on filtering the files based on their extension can be "cheated" by simply changing the file extensions of an arbitrary file.
You should therefore always check whether the opened file inside of the onCompletion
callback contains valid data, instead of assuming that the
chosen file type is always correct.
See Also
public void OpenFiles (SupportedFileType[], Action<bool, OpenedFile[]>)
Presents a native dialog to the user which allows them to select multiple
files to be opened at once. The selected file contents are then loaded
into memory managed by instances of the OpenedFile
class.