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.

kony.io.File Namespace

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.
 

kony.io.FileList Namespace

FunctionDescription
kony.io.File.itemReturns the File object at the specified index in the FileList.
 

kony.io.FileSystem Namespace

FunctionDescription
kony.io.FileSystem.browseProvides the ability to browse and select files from your local system.
kony.io.FileSystem.copyBundledRawFileToCopies 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.getApplicationDirectoryPathReturns the application directory path.
kony.io.FileSystem.getCacheDirectoryPathReturns the application's cache directory path.
kony.io.FileSystem.getDatabaseDirectoryPathReturns the application's database directory path (from application's private file system) where kony.db APIs access the database files.
kony.io.FileSystem.getDataDirectoryPathReturns the application’s data directory path.
kony.io.FileSystem.getExternalCacheDirReturns 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.getExternalCacheDirsReturns 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.getExternalFilesDirReturns 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.getExternalStorageDirectoryPathReturns the path to the external storage, typically sdcard.
kony.io.FileSystem.getExternalStorageStateReturns the current state of the shared or external storage media at the specified path.
kony.io.FileSystem.getFileReturns a kony.io.File object representing the file for the given path.
kony.io.FileSystem.getFileSystemStatsRetrieves the detailed information about the space on a file system.
kony.io.FileSystem.getNoBackupFilesDirReturns the absolute path to the directory on the file system
kony.io.FileSystem.getRawDirectoryPathReturns the application’s “raw” directory path.
kony.io.FileSystem.getSupportDirectoryPathReturns the application’s support directory path.
kony.io.FileSystem.isExternalStorageAvailableChecks if the external storage is available and accessible on the device.
kony.io.FileSystem.isExternalStorageEmulatedChecks if the external storage is emulated.
kony.io.FileSystem.isExternalStorageRemovableChecks if the external storage is physically removable.
kony.io.FileSystem.uploadFilesInternally iterates through the fileList and makes the network call to the URL mentioned and uploads the files.
 

kony.types Namespace

FunctionDescription
kony.types.RawBytes.clearClears the content that is held by the RawBytes object.
kony.types.RawBytes.getContentTypeRetrieves the Content Type of the RawBytes object.
kony.types.RawBytes.getResourcePathReturns the location of rawbytes which can be Android content URI or a file path.
kony.types.RawBytes.getTempPathReturns the path where the source files of all RawBytes are stored.
kony.types.RawBytes.readAsTextReturns 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:

  1. 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.
  2. Mobile:

    <WorkSpace>\<App>\resources\mobile\common\raw

    Tablet:

    <WorkSpace>\<App>\resources\tablet\common\raw

  3. 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.
  4. 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.

  5. In case of Android, the file name should contain only the following characters:
    • a – z (lower case)
    • 0 – 9
    • _ (underscore)
    • . (period)

    This guideline is applicable only for the Android platform.

  1. 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.
  2. NOTE: In future these values may vary based on the application store decisions for respective platforms.

OSLimitBinary Type
Android100 MB.apk
IOS60 MB.ipa
Silver light applications1 GB.xap packages

Quantum Visualizer provides the following APIs to support accessing the pre-bundled files programmatically.