Used the markup email solution and the client came back saying that the emails were blank, not adding the content on certain devices. So I set out to implement the web intent plugin (as you can see from the package name) but I ended up just implementing a new email plugin.
Here is the Java class.
package com.webintent.emailcomposer;
import org.apache.cordova.api.PluginResult;
import org.apache.cordova.api.PluginResult.Status;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Intent;
import android.net.Uri;
import android.text.Html;
import com.phonegap.api.Plugin;
public class EmailComposer extends Plugin {
public final String ACTION_SEND_EMAIL = "SendEmail";
public PluginResult execute(String action, JSONArray arg1, String callbackId) {
PluginResult result = new PluginResult(Status.INVALID_ACTION);
if (action.equals(ACTION_SEND_EMAIL)) {
try {
String email = arg1.getString(0);
String subject = arg1.getString(1);
String message = arg1.getString(2);
this.sendEmail(email, subject, message);
result = new PluginResult(Status.OK);
}
catch (JSONException ex) {
result = new PluginResult(Status.JSON_EXCEPTION, ex.getMessage());
}
}
return result;
}
private void sendEmail(String email, String subject, String message) {
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_SUBJECT, subject);
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{email});
intent.putExtra(
Intent.EXTRA_TEXT,
Html.fromHtml(new StringBuilder()
.append(message)
.toString())
);
intent.setType("text/html");
this.ctx.startActivity(Intent.createChooser(intent, "Choose email account"));
}
}
Remember to update plugins.xml
Here is the js plugin code
var EmailPlugin = function () {};
cordova.addConstructor(function() {
return cordova.addPlugin("email", new EmailPlugin());
});
EmailPlugin.prototype.send = function (email, subject, message){
cordova.exec(function(){ alert('email success')},
function(){ alert('email fail')},
'EmailComposer',
'SendEmail',
[email, subject, message]);
}
And finally, you call the plugin as such.
window.plugins.email.send(email, subject, body);
Note I didn't include callbacks in the parameters, but you can see where they would go.