0

I'm using cordova/phonegap to make a Android app and trying to call JavaScript funtion from android/native

My main acitvity:-

public class MainActivity extends CordovaActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);


        // Set by <content src="index.html" /> in config.xml
        loadUrl(Url);

        // TODO call javascripte from here 

    }
}

My index.html page

<!DOCTYPE HTML>
    <html>
      <head>
        <title>PhoneGap</title>

        <script type="text/javascript" charset="utf-8">

        function myFun(){
          alert("call from the ANDROID");
        }
        </script>

    </head>
    <body >
    </body>
    </html>

I want call JavaScript function from phonegap.

3

1 Answer 1

4

try this code

webView.loadUrl("javascript:myFun()");
Sign up to request clarification or add additional context in comments.

4 Comments

i am not using webView over here
@user5716434 then how to run your javascript?
Please check your entire project app must contain the webview, this loadUrl(Url); is used to load the html file into webview.
What if I want to get a result from JavaScript function? webView.loadUrl() is void in nature.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.