I am blackberry developer and I don't have any experience in Android programming.
I am trying to create an android application which will have webview/embedded browser. I will load some web page with some javascripts in embedded browser. There will be some buttons on the page which will call javascript functions. Some of these functions require access to native APIs (eg Camera API). Is it possible to call native api's from javascript functions or access to native code of the app ?
Right now this is possible in blackberry platform using Javascript extension. I'm expecting something similar in Android.
Thank you.
Anyone who is looking for the answer, I've found solution based on @dtanders answer. Check this out: .html#BindingJavaScript
I am blackberry developer and I don't have any experience in Android programming.
I am trying to create an android application which will have webview/embedded browser. I will load some web page with some javascripts in embedded browser. There will be some buttons on the page which will call javascript functions. Some of these functions require access to native APIs (eg Camera API). Is it possible to call native api's from javascript functions or access to native code of the app ?
Right now this is possible in blackberry platform using Javascript extension. I'm expecting something similar in Android.
Thank you.
Anyone who is looking for the answer, I've found solution based on @dtanders answer. Check this out: http://developer.android.com/guide/webapps/webview.html#BindingJavaScript
Share Improve this question edited Jul 20, 2011 at 21:10 indusBull asked Jul 20, 2011 at 19:52 indusBullindusBull 1,8545 gold badges27 silver badges42 bronze badges 2- I know little about javascript so I couldn't say for sure. But I've never come across a way that you could do that on Android. Do you already have the web app that you are loading into the WebView built? – FoamyGuy Commented Jul 20, 2011 at 20:16
- @Tim yes we already have a webapp. But I haven't created any sample native app with WebView. I want to first know if it's possible. – indusBull Commented Jul 20, 2011 at 20:23
4 Answers
Reset to default 7Use http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String) to expose Java interfaces to the JavaScript running in the WebView
Well, if you specifically want the Camera API, it can be done. From your JS code, you can call a piece of Java code which will in turn trigger the Camera App, take a picture, return the image's URL, which your Java code can forward it to a JS method.
See:
http://developer.android.com/guide/webapps/index.html http://developer.android.com/guide/webapps/webview.html
Its a complete shot in the dark on my part but these might have some useful information for you.
Webview not responding to touch events
Does Android support click events in its WebView?
Also don't forget that WebViews have javascript disabled by default you'll need to explicitly set it to true in order to make it work.