简体   繁体   English

如何在HTML按钮的“ onClick”上调用Java函数?

[英]How to call java function on “onClick” of html button?

I have a button in html file and java code for sharing image over email, now i need to put the "onclick" of button code in java to "onClick" of html to implement "Data sharing" through email in phonegap. 我在html文件中有一个按钮,并且java代码用于通过电子邮件共享图像,现在我需要将java中的按钮代码的“ onclick”放置到html的“ onClick”,以通过phonegap中的电子邮件实现“数据共享”。 since i'm new to html and phonegap i dont know the procedure, please help me. 由于我是html和phonegap的新手,所以我不知道该程序,请帮助我。

here is my java code 这是我的java代码

public class MainActivity extends Activity {

 @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);

        Button addImage = (Button) findViewById(R.id.send);
        addImage.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {


                GMailSender mailsender = new GMailSender("xya@gmail.com", "pw123");

                String[] toArr = { "abc@gmail.com", "efg@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(MainActivity.this,
                                "Email was sent successfully.",
                                Toast.LENGTH_LONG).show();
                    } else {
                        Toast.makeText(MainActivity.this, "Email was not sent.",
                                Toast.LENGTH_LONG).show();
                    }
                } catch (Exception e) {

                    Log.e("MailApp", "Could not send email", e);
                }
            }
        });

    }

html code HTML代码

<body >     
  <button onclick="  " id="email">Send_Email </button>
</body>

I think you can achieve this using a call to javascript function on click of the button. 我认为您可以通过单击按钮来调用javascript函数来实现此目的。 The javascript function can either use ajax or JQuery to upload your file. javascript函数可以使用ajax或JQuery来上传文件。 I found it in this link PhoneGap File Upload Using jQuery Ajax 我在此链接中找到它使用jQuery Ajax的PhoneGap文件上传

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM