Supported on Android, iOS, macOS and JVM targets
Quick start
The open file function allows you to open any file with the default application associated with that file type on the user’s device. This is useful for viewing documents, images, or any other file type without handling the content within your app.filekit-dialogs
.pdf files, an image viewer for .jpg files, or a text editor for .txt files.
Ensure the file you are trying to open exists and is accessible. Attempting to open a non-existent file will result in an error.
Android setup
Opening files on Android requires additional FileProvider configuration to securely share files with other applications. Starting from Android 7.0 (API level 24), Android restricts the sharing of file URIs between apps for security reasons. FileProvider generates secure content URIs that allow temporary access to specific files. Why FileProvider is required? Android uses FileProvider to:- Enhance security: Prevents exposing your app’s internal file structure to other apps
- Control access: Grants temporary, limited access to specific files only
- Maintain compatibility: Required for opening files on Android 7.0+ due to
FileUriExposedException
For detailed information about FileProvider, see the official Android documentation.
- Add the FileProvider to your
AndroidManifest.xml:
- Create
androidMain/res/xml/file_paths.xml:
Important: Include only the path type that matches your FileKit usage:
- Use
<files-path>if you useFileKit.filesDir - Use
<cache-path>if you useFileKit.cacheDir - Include both if you use both directories
- When opening files from custom locations, provide the
openFileSettingsparameter with your app’s FileProvider authority:
filekit-dialogs
If you don’t provide the correct FileProvider authority when opening files from custom locations on Android, the operation will fail with a
FileUriExposedException on Android 7.0 and above.