Input and Output API
The Input and Output API enables your app to perform common tasks such as copy, rename, and delete files. This API enables you to browse through file systems and then select multiple files to upload on the server. In addition, the I/O API enables you to manage directories, determine if external storage is available, and so forth.
The Input and Output API, often abbreviated as the I/O API, is composed of the following Namespaces.
Function | Description |
---|---|
kony.io.File.copyTo
|
Copies a file to the given destination path. |
kony.io.File.createDirectory
|
Creates a directory on the file system represented by this file object. |
kony.io.File.createFile
|
Creates a file on the file system represented by this file object. |
kony.io.File.exists
|
Checks if the file or directory exists on the file system represented by this file object. |
kony.io.File.getFilesList
|
Returns kony.io.FileList object representing the files and directories available under this file object directory. |
kony.io.File.isDirectory
|
Checks if this object represents a directory file on the file system. |
kony.io.File.isFile
|
Checks if this object represents a typical file on the file system but not a directory. |
kony.io.File.moveTo
|
Moves a file to the given destination path. |
kony.io.File.read
|
Returns the kony.types.RawBytes of this file. |
kony.io.File.remove
|
Deletes a file or a directory. |
kony.io.File.rename
|
Renames a file or a directory. |
kony.io.File.write
|
Writes the given content into the file. |
Function | Description |
---|---|
kony.io.File.item | Returns the File object at the specified index in the FileList. |
Function | Description |
---|---|
kony.io.FileSystem.browse | Provides the ability to browse and select files from your local system. |
kony.io.FileSystem.copyBundledRawFileTo | Copies a bundled file from the application binary to the specified destination path on the device. |
kony.io.FileSystem.getAppGroupDirectoryPath | Retrieves the root path of an app group. |
kony.io.FileSystem.getApplicationDirectoryPath | Returns the application directory path. |
kony.io.FileSystem.getCacheDirectoryPath | Returns the application's cache directory path. |
kony.io.FileSystem.getDatabaseDirectoryPath | Returns the application's database directory path (from application's private file system) where kony.db APIs access the database files. |
kony.io.FileSystem.getDataDirectoryPath | Returns the application’s data directory path. |
kony.io.FileSystem.getExternalCacheDir | Returns the absolute path to the directory on the primary shared or external storage device where the application can store its cached files. |
kony.io.FileSystem.getExternalCacheDirs | Returns the absolute paths to the application-specific directories on all the shared or external storage devices where the application can store its cached files. |
kony.io.FileSystem.getExternalFilesDir | Returns the absolute path to the directory on the primary shared or external storage device where the application can store its persistent files. |
kony.io.FileSystem.getExternalFilesDirs | Returns the absolute paths to the application-specific directories on all the shared or external storage devices where the application can store its persistent files. |
kony.io.FileSystem.getExternalStorageDirectoryPath | Returns the path to the external storage, typically sdcard. |
kony.io.FileSystem.getExternalStorageState | Returns the current state of the shared or external storage media at the specified path. |
kony.io.FileSystem.getFile | Returns a kony.io.File object representing the file for the given path. |
kony.io.FileSystem.getFileSystemStats | Retrieves the detailed information about the space on a file system. |
kony.io.FileSystem.getNoBackupFilesDir | Returns the absolute path to the directory on the file system |
kony.io.FileSystem.getRawDirectoryPath | Returns the application’s “raw” directory path. |
kony.io.FileSystem.getSupportDirectoryPath | Returns the application’s support directory path. |
kony.io.FileSystem.isExternalStorageAvailable | Checks if the external storage is available and accessible on the device. |
kony.io.FileSystem.isExternalStorageEmulated | Checks if the external storage is emulated. |
kony.io.FileSystem.isExternalStorageRemovable | Checks if the external storage is physically removable. |
kony.io.FileSystem.uploadFiles | Internally iterates through the fileList and makes the network call to the URL mentioned and uploads the files. |
Function | Description |
---|---|
kony.types.RawBytes.clear | Clears the content that is held by the RawBytes object. |
kony.types.RawBytes.getContentType | Retrieves the Content Type of the RawBytes object. |
kony.types.RawBytes.getResourcePath | Returns the location of rawbytes which can be Android content URI or a file path. |
kony.types.RawBytes.getTempPath | Returns the path where the source files of all RawBytes are stored. |
kony.types.RawBytes.readAsText | Returns the data as text represented by the RawBytes object. |
File Handling
The kony.io.File
Namespace consists of functions that enable you to perform common file handling tasks. Your app can create a File object to represent files in the device's file system and perform common operations on them. Now create a file using the kony.io.File.createFile
function. To verify if a file exists in the file system using the kony.io.File.exists
function. You can also check if the object represents a file or a directory using the kony.io.File.isFile
and the kony.io.File.isDirectory
functions; and return all the files in the filesystem using the kony.io.File.getFilesList
function.
To move a file, use the kony.io.File.moveTo
function. To copy a selected file use the kony.io.File.copyTo
function. You can read the data in the file using the kony.io.File.read
and the kony.io.File.readAsText
functions. You can also write in a file using kony.io.File.write
function. If you want to rename a file, use the kony.io.File.rename
function; and to delete a file, use the kony.io.File.remove
function. Using the kony.io.File.item
, you can return a file object at a specified index in the File list.
File System Handling
The kony.io.FileSystem
Namespace consists of the functions that handles a file system. Use the kony.io.FileSystem.getFile
function to get an instance of a File object. You can browse and select files from the file system using the kony.io.FileSystem.browse
function. Then get the root path of an application using the kony.io.FileSystem.getApplicationDirectoryPath
and the app group directory path using the kony.io.FileSystem.getAppGroupDirectoryPath
function. Use the kony.io.FileSystem.getCacheDirectoryPath
function to get the application cache’s directory path, the kony.io.FileSystem.getDataDirectoryPath
to get the application’s directory path, the kony.io.FileSystem.getDatabaseDirectoryPath
to get the application’s database directory path and external storage directory path using the kony.io.FileSystem.getExternalStorageDirectoryPath
function. For the application’s raw directory path, use the kony.io.FileSystem.getRawDirectoryPath
function and for the application’s support path, use the kony.io.FileSystem.getSupportDirectoryPath
function. You can also check if the external storage is available and accessible on the device using the kony.io.FileSystem.isExternalStorageAvailable
function, and upload files using the kony.io.FileSystem.uploadFiles
function.
Pre bundling Files
Kony gives an ability to bundle files such as SQLite database (pre-configured), video, image, and so on as part of an application binary. After bundling, the files can be accessed from the app at the run time on the device. You need to follow certain guidelines to bundle the files.
Here are the guidelines:
- Place the files to be bundled in the application workspace at the following locations. When you place the files in these locations, the files will be bundled with the application built for all the platforms.
- You can also place the files in the platform-specific folders. When you place the files in platform-specific folders, the files will be bundled only with the application built for that particular platform. For example, if you place the files in the android\raw folder, the files will be bundled only for the application built for the Android platform.
- In case of Android, the file name should contain only the following characters:
- a – z (lower case)
- 0 – 9
- _ (underscore)
- . (period)
Mobile:
<WorkSpace>\<App>\resources\mobile\common\raw
Tablet:
<WorkSpace>\<App>\resources\tablet\common\raw
Android Mobile:
<WorkSpace>\<App>\resources\mobile\native\android\raw
Android Tablet:
<WorkSpace>\<App>\resources\tablet\native\androidtab\raw
IOS Mobile:
<WorkSpace>\<App>\resources\mobile\native\iphone\raw
IOS Tablet:
<WorkSpace>\<App>\resources\tablet\native\ipad\raw
After placing the files either in common or platform-specific folder and build the respective application, the files are packaged in the application binary file. Example, .apk, .ipa, and so on.
In case same file is located at both common and platform-specific folders, the file in the platform-specific folder will override the file in the common folder.
This guideline is applicable only for the Android platform.
- Application binary size limitation: After bundling the files, the size of the application binary should not exceed the size defined for each platform in the table below. These size limits are specified by the platform-specific stores where the apps will be uploaded.
NOTE: In future these values may vary based on the application store decisions for respective platforms.
OS | Limit | Binary Type |
---|---|---|
Android | 100 MB | .apk |
IOS | 60 MB | .ipa |
Silver light applications | 1 GB | .xap packages |
Quantum Visualizer provides the following APIs to support accessing the pre-bundled files programmatically.