如何在react native中直接打开邮件应用程序收件箱?

wbrvyc0a  于 2022-11-25  发布在  React
关注(0)|答案(1)|浏览(177)

使用Linking.openURL('mailto:')与expo链接打开邮件应用程序与'撰写邮件'屏幕,我如何打开邮件应用程序直接在收件箱选项卡?

vwoqyblh

vwoqyblh1#

this stack overflow post的启发,你可以在iOS上使用message:// url方案来实现这一点,如果没有提供内容,则默认为iOS上的电子邮件收件箱。
对于android来说,事情有点棘手。你需要expo-intent-launcher和一些额外的参数来完成交接。一个完整的解决方案可能如下所示:

import { startActivityAsync, ActivityAction } from 'expo-intent-launcher';

    [...]
    
    if (Platform.OS === "android") {
      const activityAction = "android.intent.action.MAIN";
      const intentParams: IntentLauncher.IntentLauncherParams = {
        category: "android.intent.category.APP_EMAIL",
      };
      IntentLauncher.startActivityAsync(activityAction, intentParams);
    } 
    else if (Platform.OS === "ios") {
      Linking.openURL('message://');
    }

由于iPhone模拟器没有安装邮件客户端,因此请尽可能在真实的设备上进行测试。
List of URL schemes on wikipedia

相关问题