0
votes

https://github.com/TeamHive/capacitor-email is a Capacitor email plugin, allowing you to send emails from Ionic 4 mobile apps. I can’t get the demo to work at all in Android Studio 3.4.1, @ionic/angular 4.0.0-beta.7 and @capacitor/core 1.1.0. I get 5 build errors like:

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

If I try to use the sample code provided at the Github page in a starter Ionic app, I get a runtime error:

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

In my sample code below, based on the Github sample code, the console.log outputs this.email = {}, so new Email() is returning an empty object.

  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();
    }

Has anyone got this capacitor plugin to work at all?

1

1 Answers

2
votes

To make this plugin work, you have to edit the generated MainActivity class, and add add(EmailPlugin.class); as below.

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);
    }});
  }
}