2

要通过电子邮件共享数据,我已经在 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>

爪哇代码

  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
4

1 回答 1

0

您在添加cordova-2.4.0.jar 文件时犯了大错,但您需要添加cordova-2.4.0.js 文件

你已经完成了

    <script type="text/javascript" charset="utf-8" src="libs/cordova-2.4.0.jar">

你需要替换为

    <script type="text/javascript" charset="utf-8" src="cordova-2.4.0.js">
于 2013-09-12T06:27:11.913 回答