Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recommend new Feature: hasProvider() => Boolean #89

Open
fischey007 opened this issue Jan 19, 2023 · 0 comments
Open

Recommend new Feature: hasProvider() => Boolean #89

fischey007 opened this issue Jan 19, 2023 · 0 comments

Comments

@fischey007
Copy link

Before the user send his message or attachements to a mail provider, the app should check if there is any mail provider available. If the mail provider is not available, we don't need to trigger the method 'send' because it will not executed successfully:

i have implemented a solution for android and iOS which is similiar to actual plugin code:

android function:

 private fun hasProvider(callback: Result){
        if (activity == null) {
            callback.success(false)
            return
        }
        val intent = Intent()
        intent.action = Intent.ACTION_SENDTO
        intent.data = Uri.parse("mailto:")
        val packageManager = activity?.packageManager
        if (packageManager?.resolveActivity(intent, 0) != null) {
            callback.success(true)
        } else {
            callback.success(false)
        }
}

iOS function:

private func hasProvider(result: @escaping FlutterResult){
        guard let viewController = UIApplication.shared.keyWindow?.rootViewController else {
            result(false)
            return
        }
        if MFMailComposeViewController.canSendMail() {
            result(true)
        } else {
            result(false)
        }
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant