I am trying to run Java function which is a member of my Android app class from Javascript. My function that I am trying to run is:
public static String printName(){
return("Hello World!");
}
And my javascript code to call this method is:
<!DOCTYPE html>
<html>
<body>
<h2>Example Webpage</h2>
<p id="demo"></p>
<script>
function foo(){
var name = Packages.com.example.joey.myproject.MainActivity.printName();
return name;
}
document.getElementById("demo").innerHTML = foo();
</script>
</body>
</html>
When I run this code with a web server nothing happens. HTML part like header is working good but Javascript part isn't running. I read this (calling java method in javascript) post but I can't run JSP files for now. Please help me with the Javascript.