0

I need to pass some simple values from HTML or Javascript to Java. I have reviewed all the documentation but can't find a straight forward way.

I have a HTML form with a couple of values that are needed in Java. I'm already calling Java from Javascript just not sure how to get the data the other way around.

For instance Java is emailing a local file for me. I need to tell Java the name of the file which is named in Javascript by document.getElementById('CompanyName').value + .html.

How can I do this?

Here is the current Java code I'm using to email the file: (I need all the "test" phrases to be replaced by values from the form.)

public class JavaScriptInterface {
private WebView mAppView;
private DroidGap mGap;
public JavaScriptInterface (DroidGap gap, WebView view)
{
    mAppView = view;
    mGap = gap;
    }
public void doEmail(){

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    sendIntent.setType("text/html");
    sendIntent.putExtra(android.content.Intent.EXTRA_TEXT,"test text");
    sendIntent.putExtra(Intent.EXTRA_SUBJECT,"test subject");
    sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    sendIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///sdcard/test co.html"));
    mGap.startActivity(sendIntent);
    }
} 

1 Answer 1

1

Just add a parameter. In your case I'm assuming that your JavaScript already calls doEmail(). Change the signature to something like doEmail(String filename), use the parameter in the Java method, and when you call it, pass the parameter like:

window.whateverYouCalledThis.doEmail(document.getElementById('CompanyName').value + '.html');
Sign up to request clarification or add additional context in comments.

1 Comment

Why didn't I think of that? Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.