rememberShare

Implementation of rememberShare function on Android

Remember a sharing function that uses the native sharing mechanism of the platform.

This composable function returns a stable callback that opens the platform's native sharing interface, allowing users to share the specified file through various apps and services available on their device.

Basic Usage

@Composable
fun ShareButton() {
val share = rememberShare()

Button(
onClick = {
share(
url = "file:///path/to/your/file.jpg",
options = SharingOptions(
androidDialogTitle = "Share Image",
androidMimeType = "image/jpeg",
iosAnchor = Anchor(x = 100f, y = 100f, width = 200f, height = 50f)
)
)
}
) {
Text("Share")
}
}

File URL Requirements

The returned function supports local file URLs with the file:// and content:// scheme:

Supported:

  • file:///storage/emulated/0/Pictures/image.jpg

  • content://media/external_primary/images/media/1000002137

Not Supported:

  • https://example.com/file.jpg (remote URLs)

  • Relative paths without file:// scheme

Return

A stable Share instance that can be invoked to share files

Throws

When the URL is invalid, file doesn't exist, or URL scheme is not file://

When the sharing operation fails due to platform-specific errors

actual fun rememberShare(): Share

Implementation of rememberShare function on iOS