📚 Encyclopedia

Android · updated 2026-10-13

Making a Flutter app an Android share target (native, no plugin)

androidfluttershare-intenteventchannelkotlinintent-filteruploadsplugins

TLDR appears in Android's share sheet: share a photo, video, PDF or any file and it opens a new post with the file uploaded and embedded. It is implemented with about 80 lines of Kotlin and 30 lines of Dart over an EventChannel, because every share plugin on pub.dev failed to build with a modern toolchain. The pattern generalizes to any small Android integration.

Why not a plugin

receive_sharing_intent (stale, hardcoded Kotlin 1.9.22 / JVM 1.8), share_handler (open build errors, Kotlin 1.8.22) and flutter_sharing_intent (JVM 1.8) all produced JVM target mismatch errors against Kotlin 2.2, AGP 8.11, Gradle 8.14 and JVM 17. Rule that came out of it: before flutter pub add, check last release date (reject if stale beyond ~6 months), its Kotlin/AGP/JVM targets versus yours, and open build-failure issues; for small platform features prefer a native MethodChannel/EventChannel.

Manifest

Declare the widest filter you can actually handle. The first version listed image/*, application/pdf, text/plain, application/octet-stream, so videos, audio, zips and Office documents never offered the app. The working filter:

<intent-filter>
  <action android:name="android.intent.action.SEND"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="*/*"/>
</intent-filter>
<intent-filter>
  <action android:name="android.intent.action.SEND_MULTIPLE"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <data android:mimeType="*/*"/>
</intent-filter>

Kotlin side (MainActivity)

Dart side

The 2 MB phantom limit

After this shipped, a 7 MB photo was rejected as "too large (max 2 MB)" although the server allowed 500 MB. The client's upload-status call omitted the auth token, got 401, swallowed it, and kept a hardcoded 2 MB default. Fix: send the token, and make the fallback default generous so a failed status check can never block a file the server would accept. Found by grepping the nginx access log for 401s from the app's Dart/ user agent. See Debugging client-side bugs from the server's access log.

Gotchas

See also

Linked from

Sources: tldr memory (feature-share-intent, feedback_package_research, bug-upload-status-401-2mb), posts #1712, #1716, #1719