shareImage
Android actual: writes the PNG into the app's cache and shares it as a content:// stream.
The FileProvider is declared by the HOST APP, not by this module. AGP's Kotlin-Multiplatform library plugin merges an androidMain manifest but does not package androidMain/res, so a provider declared here fails at link time with resource xml/... not found. Shipping the declaration from the app is also the conventional wiring, and it keeps the app in control of which directories it exposes. canShareImage reports whether the app actually did it.
Required in the app's manifest:
<provider android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.kmpshare"
android:exported="false" android:grantUriPermissions="true">
<meta-data android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/kmp_share_paths" />
</provider>with res/xml/kmp_share_paths.xml granting only <cache-path name="kmp-share" path="kmp-share/" />.
Never throws. Every failure here is a share action, whose caller's fallback is to share text.
Shares an image with accompanying text through the platform share sheet.
Mirrors shareText deliberately, including its honesty about coverage: Android and iOS are implemented; JVM and wasm are no-ops because no share sheet exists there, exactly as shareText is. A caller that needs a guaranteed share should call shareText when shareImage is unavailable rather than assume this landed — see canShareImage.
Parameters
the encoded image (see ImageBitmap.toPngBytes() in :designsystem).
base name without extension; sanitised by the platform actual.
iOS actual: writes the PNG into the temporary directory and hands its file URL to the share sheet alongside text, mirroring what the Android actual does with a content:// stream.
A file URL rather than a UIImage so fileName survives into whatever the user shares to — Mail attaches it by name, Files saves it by name. The temporary directory is the system's to reclaim, so nothing here has to clean up after a share the app never learns the outcome of.
Never throws, and never silently does nothing. canShareImage returns true on iOS, so a caller has already skipped its own text fallback by the time it gets here — returning quietly on a failed write would reproduce exactly the silent no-op this actual was written to remove. Both failure paths therefore degrade to shareText rather than to nothing.
Not implemented on this target yet, matching shareText. canShareImage reports it honestly.
Not implemented on this target yet, matching shareText. canShareImage reports it honestly.