Reputation: 877
I'm opening an email client from my Ionic app using:
window.open('mailto:[email protected]?subject=Test Subject');
This works fine if the device does has an email client installed, but if not, this line causes nothing to happen.
Is there a way to check for at least one installed email client ahead of time in Ionic, or a way to determine whether this operation failed because no app is installed that can handle it? I'd like to alert the user in cases where they do not have an email client installed.
Upvotes: 0
Views: 435
Reputation: 877
I never really found an solution specifically for this issue, but here's some input on what I found:
I tried out the Email Composer native plugin. The issue is that in Android it requests permissions to access all of your contacts for some reason, and there is no configuration to disable this permissions check.
I tried out the App Availability native plugin, but this only allows checking for specific app package names in Android.
So we ended up just creating an endpoint to handle an in-app form submission instead of attempting to open their native email client. If you don't have a server, you could pretty easily set this up with whatever email integration solution you are using.
Upvotes: 0
Reputation:
On your a
or (click)
or (tap)
or (ionChange)
put a function and inside the function
function SendEmail() {
const windowRef = window.open('mailto:[email protected]?subject=Test Subject');
windowRef.focus();
setTimeout(function(){
if(!windowRef.document.hasFocus()) {
windowRef.close();
}
}, 500);
}
And you can manage here the problem.
Here the idea
Upvotes: 1