電子メールでデータを共有するには、Android ネイティブ コードでこれを行いました。hmtl ボタンの「onClick」で電子メール関数を呼び出す必要があります。しかし、ここでは電子メール機能が起動されておらず、この問題を修正するために logcat でエラーが発生しませんでした。助けてください
htmlファイル
<!DOCTYPE HTML>
<html>
<head>
<link rel="stylesheet" href="index.css" />
<script type="text/javascript" charset="utf-8" src="libs/cordova-2.4.0.js"> </script>
<script type="text/javascript" charset="utf-8" src="social.js"></script>
<script type="text/javascript" charset="utf-8" src="Esocial.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}
function onDeviceReady()
{
window.SocialShare = new SocialShare();
console.log("in onDeviceReady");
}
function sendEmail()
{
SocialShare.Email= function(param, successCallback, failCallback) {
window.SocialShare.email({message:'Email body', subject: "Email Subject"},
function(msg) {
alert('Write Some real Text please.');
},
function(fail) {
}
);
}
}
</script>
</head>
<body onload="onLoad()">
<button onclick="sendEmail()" id="email">Email send </button>
</body>
</html>
Java コード
public class SocialShare extends CordovaPlugin{
private String callback;
Context context;
public PluginResult execute(String action, JSONArray args, String callbackId) {
try
{
if( action.equals("startEmailActivity") )
{
JSONObject obj = args.getJSONObject(0);
String msg = obj.has("message") ? obj.getString("message") : "";
String subject = obj.has("subject") ? obj.getString("subject") : "";
startEmailActivity(msg, subject );
}
}
catch (JSONException e) {
e.printStackTrace();
return new PluginResult(PluginResult.Status.JSON_EXCEPTION);
}
PluginResult mPlugin = new PluginResult(PluginResult.Status.NO_RESULT);
mPlugin.setKeepCallback(true);
this.callback = callbackId;
return mPlugin;
}
public void startEmailActivity ( String msg, String emailaddress )
{
GMailSender mailsender = new GMailSender("abc@gmail.com", "xxxxx");
String[] toArr = { "abc@gmail.com", "abc@gmail.com" };
mailsender.set_to(toArr);
mailsender.set_from("sender@gmail.com");
mailsender.set_subject("This is an email sent using my Mail JavaMail wrapper from an Android device.");
mailsender.setBody("Email body.");
try {
//mailsender.addAttachment("/sdcard/filelocation");
if (mailsender.send()) {
Toast.makeText(context,
"Email was sent successfully.",
Toast.LENGTH_LONG).show();
} else {
Toast.makeText(context, "Email was not sent.",
Toast.LENGTH_LONG).show();
}
} catch (Exception e) {
Log.e("MailApp", "Could not send email", e);
}
}
}
config.xml に追加されたプラグイン
<plugin name="SocialShare" value="com.gmail.plugins.SocialShare"/>
ロケート出力
08-29 09:56:18.934: D/dalvikvm(2566): GC_FOR_ALLOC freed 35K, 6% free 2475K/2632K, paused 88ms, total 90ms
08-29 09:56:18.944: I/dalvikvm-heap(2566): Grow heap (frag case) to 3.139MB for 635812-byte allocation
08-29 09:56:19.054: D/dalvikvm(2566): GC_FOR_ALLOC freed 1K, 5% free 3095K/3256K, paused 109ms, total 109ms
08-29 09:56:19.104: D/dalvikvm(2566): GC_CONCURRENT freed <1K, 5% free 3100K/3256K, paused 4ms+11ms, total 50ms
08-29 09:56:19.224: D/JsMessageQueue(2566): Set native->JS mode to 2
08-29 09:56:19.423: D/gralloc_goldfish(2566): Emulator without GPU emulation detected.
08-29 09:56:20.644: D/chromium(2566): Unknown chromium error: -6
08-29 09:56:22.944: D/TilesManager(2566): Starting TG #0, 0x2a2600f8