简体   繁体   中英

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. since i'm new to html and phonegap i dont know the procedure, please help me.

here is my java code

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

<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. The javascript function can either use ajax or JQuery to upload your file. I found it in this link PhoneGap File Upload Using jQuery Ajax

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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