Skip to content

Commit 6c314c3

Browse files
authored
🔀 Merge pull request #380 from vinceglb/docs/add-open-file-documentation
📝 Add open file documentation for FileKit.openFileWithDefaultApplication()
2 parents 1924a63 + ed8141d commit 6c314c3

File tree

4 files changed

+54
-9
lines changed

4 files changed

+54
-9
lines changed

docs/dialogs/open-file.mdx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: 'Open file dialog'
3+
sidebarTitle: 'Open file'
4+
description: 'Open a file with the default application in a Kotlin Multiplatform project'
5+
---
6+
7+
import AndroidFileProviderSetup from '/snippets/android-fileprovider-setup.mdx'
8+
9+
<Check>Supported on Android, iOS, macOS and JVM targets</Check>
10+
11+
## Quick start
12+
13+
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.
14+
15+
```kotlin filekit-dialogs
16+
val file = PlatformFile("/path/to/document.pdf")
17+
FileKit.openFileWithDefaultApplication(file)
18+
```
19+
20+
This will open the file using the system's default application for that file type - for example, a PDF viewer for `.pdf` files, an image viewer for `.jpg` files, or a text editor for `.txt` files.
21+
22+
<Info>
23+
Ensure the file you are trying to open exists and is accessible. Attempting to open a non-existent file will result in an error.
24+
</Info>
25+
26+
## Android setup
27+
28+
<AndroidFileProviderSetup />
29+
30+
3. When opening files from custom locations, provide the `openFileSettings` parameter with your app's FileProvider authority:
31+
32+
```kotlin filekit-dialogs
33+
val file = FileKit.filesDir / "document.pdf"
34+
FileKit.openFileWithDefaultApplication(
35+
file = file,
36+
openFileSettings = FileKitOpenFileSettings(
37+
authority = "${context.packageName}.fileprovider"
38+
)
39+
)
40+
```
41+
42+
<Warning>
43+
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.
44+
</Warning>

docs/dialogs/share-file.mdx

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,6 @@ Ensure the file you are sharing exists and is accessible. Sharing a non-existent
4646

4747
## Android setup
4848

49-
Using the share file dialog 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.
50-
51-
### Why FileProvider is required
52-
53-
Android uses FileProvider to:
54-
- **Enhance security**: Prevents exposing your app's internal file structure to other apps
55-
- **Control access**: Grants temporary, limited access to specific files only
56-
- **Maintain compatibility**: Required for sharing files on Android 7.0+ due to `FileUriExposedException`
57-
5849
<AndroidFileProviderSetup />
5950

6051
3. When sharing files from custom locations, provide the `shareSettings` parameter with your app's FileProvider authority:

docs/docs.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"dialogs/camera-picker",
4545
"dialogs/file-saver",
4646
"dialogs/share-file",
47+
"dialogs/open-file",
4748
"dialogs/dialog-settings"
4849
]
4950
},

docs/snippets/android-fileprovider-setup.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
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.
2+
3+
**Why FileProvider is required?**
4+
5+
Android uses FileProvider to:
6+
- **Enhance security**: Prevents exposing your app's internal file structure to other apps
7+
- **Control access**: Grants temporary, limited access to specific files only
8+
- **Maintain compatibility**: Required for opening files on Android 7.0+ due to `FileUriExposedException`
9+
110
When using custom file locations on Android, you need to configure a FileProvider in your app:
211

312
<Info>

0 commit comments

Comments
 (0)