Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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.</p> <p>Here is the Java class.</p> <pre><code>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")); } } </code></pre> <p>Remember to update plugins.xml</p> <p>Here is the js plugin code</p> <pre><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]); } </code></pre> <p>And finally, you call the plugin as such.</p> <pre><code>window.plugins.email.send(email, subject, body); </code></pre> <p>Note I didn't include callbacks in the parameters, but you can see where they would go.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload