Is there a way to launch mail app using Linking
on Android.
The point is the scheme (Deep link) mesage:
is working only on iOS.
Here is a little example which work on iOS but not on Android:
Linking.canOpenURL('message:0').then(supported => {
if (!supported) {
console.log('Can\'t handle url');
} else {
return Linking.openURL('message:0');
}
});
Many posts official/non official talks about an activity Intent or about the scheme mailto:
but I don't want to write an email. I would like to open the mail app than the user could check the email I sent him.
By the way, I'm using react-native.
I resolved this problem with a Native Module in RN
Firstly the cross platform code in JS to open the mailbox:
openMailApp() {
if (Platform.OS === 'android') {
NativeModules.UIMailLauncher.launchMailApp(); // UIMailLauncher is the
return;
}
Linking.openURL('message:0'); // iOS
return;
}
Linking is a cross platform provided by React-Native. Anyway, the URL message:0
did not work on Android.
The only solution that I found is to create an intern wrapper in my app and to create a ReactMethod in Java.
@ReactMethod
public void launchMailApp() {
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_APP_EMAIL);
getCurrentActivity().startActivity(intent);
}
If you already developed native code using React-Native framework, this is a basic ReactMethod where
private static final String REACT_MODULE = "UIMailLauncher";
@Override
public String getName() {
return REACT_MODULE;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With