Am, quite new to Phone gap and JavaScript. If any one provide with sample or sugesstion thats would helps a lot.
Exception : I got following exception : Uncaught TypeError: Object [object Object] has no method 'getName'
public class ViewerActivity extends DroidGap {
private CordovaActivity mGap;
private WebView mWebView;
WebView mWebView;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mWebView=new WebView(this);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new JavaScriptInterfaceClass (), "jsinterface");
mWebView.loadUrl("file:///android_asset/www/sample.html");
}
}
Java Interface class:
public class JavaScriptInterfaceClass {
public WebView mAppView;
public DroidGap mGap;
public JavaScriptInterfaceClass(DroidGap gap, WebView view) {
this.mAppView = view;
this.mGap = gap;
}
public String getName() {
return "android";
}
}
HTML :
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="css-js/jquery.mobile-1.0a3.min.css" />
<script src="css-js/jquery-1.5.min.js"></script>
<script src="css-js/jquery.mobile-1.0a3.min.js"></script>
</head>
<body>
<script>
function myFunction()
{
var name = jsinterface.getName();
alert("Hello! I am an alert box!"+name);
}
</script>
<input type="button" onclick="myFunction()" value="Show alert box" />
</body>
</html>