> ## Documentation Index
> Fetch the complete documentation index at: https://filekit.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Open with default app

> Open a file in the app the system associates with its type, such as a PDF viewer

[See the platform support matrix](https://filekit.mintlify.site/platform-support.md#filekit-dialogs)

Hand a file to the app the system associates with its type: a PDF viewer for `.pdf`, an image viewer for `.jpg`. Your app doesn't read the content. The function is not available on the web, so call it from a non-web source set such as `nonWebMain` (see [shared source sets](https://filekit.mintlify.site/platform-support.md#use-platform-specific-apis-from-shared-code)).

## Usage

`openFileWithDefaultApplication` is a regular function, not a suspend function, so you can call it directly from a click handler. There is no Compose launcher.

```kotlin theme={null}
val file = FileKit.filesDir / "report.pdf"
FileKit.openFileWithDefaultApplication(file)
```

## Options

**file** `PlatformFile`

The file to open. It must exist.

**openFileSettings** `FileKitOpenFileSettings` (default: createDefault())

Platform-specific settings.

**properties**

**authority** `String?` (default: null)

FileProvider authority, only needed for files outside `filesDir` and `cacheDir`. When `null`, FileKit uses its bundled `${applicationId}.FileKitFileProvider`. See [Android setup](#android-setup).

## Platform notes

Failures are reported differently on each platform. Only the JVM wraps some of them in `FileKitDialogException`:

| Platform | Behavior |
| - | - |
| Android | Sends an `ACTION_VIEW` intent with the MIME type of the file extension. Throws `ActivityNotFoundException` when no app handles that type, and `IllegalArgumentException` for a file outside the directories its FileProvider covers. |
| iOS | Calls `openURL`. If that fails, shows the "Open in" menu (`UIDocumentInteractionController`) so the user can pick an app. Reports no error. |
| macOS | Uses `NSWorkspace`. Reports no error. |
| JVM | Uses `java.awt.Desktop.open` when the desktop supports opening files. Otherwise (headless setups, Linux without GNOME libraries), on Linux it falls back to `xdg-open` and waits up to half a second for it to report an error. Throws `FileKitDialogException` when neither works: `Desktop` cannot open files and `xdg-open` is missing, cannot start, or exits with an error code. Errors from `Desktop.open` itself are not wrapped, such as `IOException` when no app is associated. |
| Linux native | Starts `xdg-open` without waiting for it. Throws `FileKitException` only if the process cannot start. |
| Windows native | Calls `ShellExecuteW` with the `open` verb. Reports no error. |
| Web | Not available. |

## Android setup

Only needed for files outside `FileKit.filesDir` and `FileKit.cacheDir`. `filekit-dialogs` already ships a FileProvider (`${applicationId}.FileKitFileProvider`) that covers those two directories, and `content://` files returned by the pickers need no provider at all. For any other location, such as `getExternalFilesDir()`, `FileProvider` throws an `IllegalArgumentException` until you declare your own provider.

**1. Declare a provider in your manifest**

```xml AndroidManifest.xml theme={null}
<provider
    android:name="androidx.core.content.FileProvider"
    android:authorities="${applicationId}.fileprovider"
    android:exported="false"
    android:grantUriPermissions="true">
    <meta-data
        android:name="android.support.FILE_PROVIDER_PATHS"
        android:resource="@xml/file_paths" />
</provider>
```

**2. List the directories it may expose**

Add one entry per location you use, for example app-specific external storage:

```xml res/xml/file_paths.xml theme={null}
<paths>
    <external-files-path name="external_files" path="." />
</paths>
```

See [FileProvider](https://developer.android.com/reference/androidx/core/content/FileProvider) for every path type.

**3. Pass the authority to FileKit**

The `authority` parameter exists only on Android, so build these settings in `androidMain`:

```kotlin androidMain theme={null}
val authority = "${FileKit.context.packageName}.fileprovider"

FileKitOpenCameraSettings(authority = authority) // camera picker
FileKitShareSettings(authority = authority) // share file
FileKitOpenFileSettings(authority = authority) // open with default app
```

## Related

* [Share file](https://filekit.mintlify.site/dialogs/share-file.md) to send a file to another app.
* [File picker](https://filekit.mintlify.site/dialogs/file-picker.md) to let the user choose one.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.