FileIntents
System-level file integration for Zynth applications, enabling “Open In”, “Share”, and “Export to System” capabilities.
@zynthjs/file-intents allows your application to interact with other apps on the device by passing file references via native intents. It leverages the Activity View Controller on iOS and Intents with FileProvider on Android.
Basic usage
Opening a File
The openAsync method triggers the system’s “Open In” menu, allowing the user to choose an external application to view or edit the file.
import { FileIntents } from "@zynthjs/file-intents";
const viewPdf = async (uri: string) => {
await FileIntents.openAsync({
uri,
mimeType: "application/pdf"
});
};
Sharing Content
The shareAsync method invokes the native system share sheet. You can share multiple files, raw text, or both.
const shareLogs = async (logUri: string) => {
await FileIntents.shareAsync({
files: [{ uri: logUri, filename: "app-logs.txt" }],
text: "Check out these logs from my Zynth app!",
subject: "App Diagnostics"
});
};
Advanced
Exporting to Files or Downloads
Use exportAsync to prompt the user to save a file from your app’s sandbox to a permanent location like the “Downloads” folder or “iCloud Drive”.
const saveDocument = async (tempUri: string) => {
const result = await FileIntents.exportAsync({
uri: tempUri,
suggestedName: "Official_Report.pdf",
target: "downloads" // Or "files"
});
if (!result.cancelled) {
console.log("File exported to:", result.destinationUri);
}
};
Special cases
- iOS Platform Nuance: On iOS, both
openAsyncandshareAsyncutilize the system-level interaction sheet (UIDocumentInteractionControllerandUIActivityViewControllerrespectively). Functionally, this meansopenAsyncpresents the “Copy to / Open in” menu, which is similar to the standard share sheet but prioritized for document handling. - App Sandbox Restriction: For security reasons, Zynth restricts
FileIntentsto files located within the application’s secure sandbox (Internal Files or Cache). Attempting to open or share files located outside these directories (e.g., system root) will result in aSecurityException. - Native Implementation:
- On iOS, successful sharing and opening use
UIActivityViewControllerandUIDocumentInteractionController. Exporting uses theUIDocumentPickerViewControllerwith.forExporting. - On Android, the library uses a built-in
FileProviderto safely grant temporary URI access to the receiving application. No manualAndroidManifestorapp.jsonconfiguration is required forFileIntentsto function.
- On iOS, successful sharing and opening use
- URI Schemes: Only
file://andcontent://(Android) URIs are supported. Passinghttp://orhttps://URLs to these methods will result in an error; use@zynthjs/networkor@zynthjs/webviewfor remote URLs.
API Reference
FileIntents Methods
openAsync(options: OpenFileOptions): Promise<void>shareAsync(options: ShareFilesOptions): Promise<void>exportAsync(options: ExportFileOptions): Promise<ExportFileResult>isAvailable(): boolean
ExportFileOptions (Type)
uri: string: Local URI of the file to export.suggestedName?: string: Default filename provided to the user.target?: 'files' | 'downloads': Preferred destination (Downloads is Android only; iOS defaults to Files).mimeType?: string: Explicit MIME type for the exported file.