Skip to content

Conversation

@miquelbeltran
Copy link
Member

@miquelbeltran miquelbeltran commented Dec 28, 2020

Description

In flutter/flutter#71518 the author requested a way to be able to launch Intents with the createChooser wrapper.

In this PR I have added the method channel launchChooser which allows users to do that.

Usage:

final intent = const AndroidIntent(
  action: 'android.intent.action.SEND',
  type: 'plain/text',
  data: 'text example',
);
intent.launchChooser('Chose an app');

Related Issues

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process. Updating the pubspec.yaml and changelogs is not required.

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • My PR includes unit or integration tests for all changed/updated/fixed behaviors (See [Contributor Guide]).
  • All existing and new tests are passing.

Note: I have added e2e and unit tests, but there's also some Espresso Android tests which won't even run, so I couldn't add anything there.

  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (flutter analyze) does not report any problems on my PR.
  • I read and followed the [Flutter Style Guide].
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • No, this is not a breaking change.

* @see #buildIntent(String, Integer, String, Uri, Bundle, String, ComponentName, String)
* @return Whether the package manager found {@link android.content.pm.ResolveInfo} using its
* {@link PackageManager#resolveActivity(Intent, int)} method.
* @see #buildIntent(String, Integer, String, Uri, Bundle, String, ComponentName, String)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think the java formatter moved this line

@nerder
Copy link

nerder commented Dec 28, 2020

Hey @miquelbeltran thank you so much for this, it looks very good so far. One question, there is a way in which i can try this out in my codebase to validate if this indeed solves my issue?

@miquelbeltran
Copy link
Member Author

Yes indeed! You can clone this repo, checkout the branch mb-issue-71518 and then you can add the dependency to android_intent_plus by path (see: https://dart.dev/tools/pub/dependencies#path-packages)

Note that the action, category, etc. must match the Android constants. I actually tried your email example and the OS told me "there's no app available" 🤷, but at least the chooser intent was launched.

@nerder
Copy link

nerder commented Dec 28, 2020

Ok, i'll try that!

In my use case i'm attempting to open the inbox (not sending an email) with the following code:

      AndroidIntent intent = AndroidIntent(
        action: 'android.intent.action.MAIN',
        category: 'android.intent.category.APP_EMAIL',
      );

Now i'll try to see what happen if i try to launch the chooser using that intent

I'll let you know 👍🏼

@miquelbeltran
Copy link
Member Author

Just tried your example and seems to work, it opened the GMail app although there was no chooser displayed (maybe because I have no other apps)

@nerder
Copy link

nerder commented Dec 28, 2020

From the answers I was able to get online seems like there is no "easy" way of accomplish that. There are some complex workaround such as this one: https://stackoverflow.com/a/42532719/4420152

But i guess there are no easy way to do that only using this plugin

@miquelbeltran miquelbeltran merged commit 0dd91df into main Jan 3, 2021
@miquelbeltran miquelbeltran deleted the mb-issue-71518 branch January 3, 2021 08:29
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants