首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法让@TeamHive/capacitor email在Ionic 4中工作

无法让@TeamHive/capacitor email在Ionic 4中工作
EN

Stack Overflow用户
提问于 2019-07-09 12:24:17
回答 1查看 639关注 0票数 0

https://github.com/TeamHive/capacitor-email是一个电容电子邮件插件,允许您从Ionic 4移动应用程序发送电子邮件。我无法让演示在Android Studio 3.4.1,@ionic/angular 4.0.0-beta.7和@capacitor/core 1.1.0中工作。我得到了5个构建错误,比如:

ERROR: Unable to resolve dependency for ':app@debug/compileClasspath': Could not resolve project :capacitor-android-plugins.

如果我尝试在starter Ionic应用程序中使用Github页面提供的示例代码,我会得到一个运行时错误:

E/Capacitor/Plugin/Console: ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'requestPermission' of undefined

在我下面的样例代码中,基于Github样例代码,console.log输出this.email = {},所以new Email()返回一个空对象。

代码语言:javascript
复制
  email: Email;

  constructor() { }

  ngOnInit() {
    this.email = new Email();
    console.log('this.email = ' + JSON.stringify(this.email));
  }

  async sendEmail() {

    try {
      await this.email.hasPermission();
    } catch (e) {
      await this.email.requestPermission();
    }

有没有人用过这个电容器插件?

EN

回答 1

Stack Overflow用户

发布于 2019-07-17 11:37:58

要使这个插件工作,您必须编辑生成的MainActivity类,并添加add(EmailPlugin.class);,如下所示。

代码语言:javascript
复制
import com.meetmaestro.hive.capacitor.email.EmailPlugin;

public class MainActivity extends BridgeActivity {
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initializes the Bridge
    this.init(savedInstanceState, new ArrayList<Class<? extends Plugin>>() {{
      // Additional plugins you've installed go here
      // Ex: add(TotallyAwesomePlugin.class);
      add(EmailPlugin.class);
    }});
  }
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56945330

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档