Skip to content

fix false “no email Managers available” on Android 11+ (SENDTO without attachments)#67

Open
taljacobson wants to merge 3 commits intomasterfrom
bugfix/no-attachments-android
Open

fix false “no email Managers available” on Android 11+ (SENDTO without attachments)#67
taljacobson wants to merge 3 commits intomasterfrom
bugfix/no-attachments-android

Conversation

@taljacobson
Copy link
Owner

Android: fix false “no email Managers available” on Android 11+ (SENDTO without attachments)

Summary

  • Fixes a false PlatformException when sending email without attachments on Android 11+.

Reproduction

  • Fresh install on a recent Android device (e.g., Pixel 8 Pro, Android 16).
  • Call send() with subject/body and no attachments.
  • Actual: “no email Managers available.” With an attachment it works.

Root cause

  • The plugin pre-queried PackageManager for ACTION_SENDTO (mailto:). On Android 11+, package visibility restrictions often make this query return empty unless the host app declares <queries>.

Changes

  • Remove PackageManager pre-query/resolve for ACTION_SENDTO.
  • Start the implicit intent directly via startActivityForResult and only report an error if ActivityNotFoundException is thrown.
  • Respect appSchema via intent.setPackage(...) when provided.
  • Preserve attachment flow with FLAG_GRANT_READ_URI_PERMISSION.

Behavior

  • Chooser is shown when available; if no handler exists, a real error is returned.

Compatibility

  • No Dart API changes.
  • No <queries> required for this flow (optional for isAppInstalled).

Testing

  • Verified on Pixel 8 Pro (Android 16): no-attachment send shows chooser; attachments work unchanged.
  • Example app builds and runs after Gradle migration.

Example project updates

  • Migrate to Flutter’s declarative Gradle plugins (dev.flutter.flutter-plugin-loader / dev.flutter.flutter-gradle-plugin).
  • Bump compileSdk to 36.
  • Migrate to embedding v2.

Related issues

Changelog

  • Bump version to 3.0.2 with the Android fix and example build migration.

…ttachment SENDTO)

- Symptom: Fresh install, send mail with subject/body and no attachment shows “no email Managers available” (Pixel 8 Pro / Android 16). Works with attachments. Choosing “Always” for a mail app masks the issue; “Only once” keeps failing.
- Root cause: Pre-querying PackageManager for ACTION_SENDTO (mailto:) is blocked by Android 11+ package visibility unless declared in <queries> or a default app exists, so queries return empty even when handlers are available. With attachments, ACTION_SEND remains discoverable.
- Fix: Remove PackageManager pre-query/resolve for SENDTO and start the implicit intent directly (startActivityForResult), catching ActivityNotFoundException to report real absence only. Preserves chooser UX and default behavior (“Only once”/“Always”). Keep appSchema via setPackage and attachment flow with FLAG_GRANT_READ_URI_PERMISSION unchanged.
@taljacobson taljacobson requested a review from Copilot September 2, 2025 16:42
@github-actions github-actions bot added Android android related issues example labels Sep 2, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes a false "no email Managers available" error on Android 11+ when sending emails without attachments. The issue was caused by package visibility restrictions that made PackageManager queries return empty results unless specific queries were declared in the manifest.

  • Removes PackageManager pre-query for ACTION_SENDTO intent and launches intent directly
  • Migrates example Android build to Flutter's declarative Gradle plugins
  • Updates Android compileSdk to 36 and migrates to embedding v2

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pubspec.yaml Bumps version to 3.0.2 for the Android fix
example/android/settings.gradle Migrates to declarative Gradle plugin management
example/android/build.gradle Removes buildscript block in favor of declarative plugins
example/android/app/src/main/java/com/dataxad/flutter_mailer_example/EmbeddingV1Activity.java Updates import to use embedding v2 FlutterActivity
example/android/app/build.gradle Migrates to declarative plugins and updates compileSdk to 36
android/src/main/java/com/dataxad/flutter_mailer/MethodCallHandlerImpl.java Fixes Android 11+ email sending by removing PackageManager pre-query
CHANGELOG.md Documents the Android fix and example migration changes

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +75 to +78
} catch (ActivityNotFoundException e) {
result.error("not_available", "no email Managers available", null);
mResult = null;
}
Copy link

Copilot AI Sep 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The variable mResult is being set to null in the catch block, but it's also set to null in the existing catch block for FlutterMailerException below. Consider extracting this cleanup into a helper method to avoid duplication.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Android android related issues example

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android 11 Unhandled Exception: PlatformException(not_available, no email Managers available, null, null)

2 participants