Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/cmake/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用react native[Android]启动邮件应用程序_Android_React Native - Fatal编程技术网

使用react native[Android]启动邮件应用程序

使用react native[Android]启动邮件应用程序,android,react-native,Android,React Native,有没有办法在Android上使用链接启动邮件应用程序。 关键是方案(深度链接)mesage:仅在iOS上运行 下面是一个在iOS上工作但在Android上不工作的小例子: Linking.canOpenURL('message:0').then(supported => { if (!supported) { console.log('Can\'t handle url'); } else { return Linking.openURL('message:0');

有没有办法在Android上使用
链接启动邮件应用程序。
关键是方案(深度链接)
mesage:
仅在iOS上运行

下面是一个在iOS上工作但在Android上不工作的小例子:

Linking.canOpenURL('message:0').then(supported => {
  if (!supported) {
    console.log('Can\'t handle url');
  } else {
    return Linking.openURL('message:0');
  }
});
许多官方/非官方的帖子谈论活动意图或计划
mailto:
,但我不想写电子邮件。我想打开邮件应用程序,这样用户就可以检查我发给他的电子邮件了

顺便说一下,我使用的是react native。

尝试使用“mailto”意图,但使用的是
意图。ACTION\u VIEW
而不是send:


要激发意图,您可以使用
链接.openURL
API:

import { Linking } from 'react-native'
Linking.openURL("mailto:?to=blah@hotmail.com");
这是因为从文档中可以看出:

可以使用{@code Intent.ACTION\u VIEW}打开的任何URL


我用RN中的本机模块解决了这个问题

首先,JS中打开邮箱的跨平台代码:

openMailApp() {
    if (Platform.OS === 'android') {
      NativeModules.UIMailLauncher.launchMailApp(); // UIMailLauncher is the 
      return;
    }
    Linking.openURL('message:0'); // iOS
    return;
  }
链接是React Native提供的跨平台。无论如何,URL
消息:0
在Android上不起作用。 我找到的唯一解决方案是在我的应用程序中创建一个intern包装器,并在Java中创建一个ReactMethod

  @ReactMethod
  public void launchMailApp() {
      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.addCategory(Intent.CATEGORY_APP_EMAIL);
      getCurrentActivity().startActivity(intent);
  }
如果您已经使用React native framework开发了本机代码,那么这是一种基本的React方法,其中

  private static final String REACT_MODULE = "UIMailLauncher";

  @Override
  public String getName() {
      return REACT_MODULE;
  }

此本机模块将打开邮件应用程序

import * as React from "react";
import { View, Button } from "react-native";
import launchMailApp from "react-native-mail-launcher";

export default class Example extends React.Component {
  render() {
    return (
      <View>
        <Button onPress={launchMailApp}>Go to mail client</Button>
      </View>
    );
  }
}
import*as React from“React”;
从“react native”导入{View,Button};
从“react native mail launcher”导入launchMailApp;
导出默认类示例扩展了React.Component{
render(){
返回(
转到邮件客户端
);
}
}

因为消息不是方案。即使是-为什么它会打开电子邮件?消息应用程序和电子邮件应用程序通常不是一回事。请尝试使用scheme mailto:的url,或者使用电子邮件MIME类型,如中所示,deep link和magi link是两种截然不同的东西,这两种东西都不是您要做的。我使用的是React-Native,我不能使用Intent API,只能使用React-Native提供的链接API。而
消息
是一个在iOS上的方案。。。它打开mail iOS应用程序,如果它使某些事情变得更简单,您可以随时从ReactNative拖放到Native。在react native工作中,这是一个非常重要的要求。是的,我就是这么做的,我为Android制作了一个本机模块,感谢您之前的回答;)我是React Native,我想使用
链接
API,我已经考虑了
意图。操作视图
但这不可能从
链接
API打开邮件撰写,我想从我的应用发送邮件,并添加从我的应用打开邮件应用的功能,用户可以查看他们的电子邮件;)我为这项工作制作了一个本地模块,它运行得非常好,非常酷@liroopier-请分享你的本地模块。感谢分享有用的信息。我需要
intent.setFlags(intent.FLAG\u活动\u新任务)在Java代码上。在当前应用程序的相同活动中启动电子邮件应用程序,但没有。基于此帖子,我为您创建了一个npm包: