从调用嵌入的WebView的JavaScript函数Android原生的API [英] Calling android native APIs from javascript functions of embedded WebView

查看:151
本文介绍了从调用嵌入的WebView的JavaScript函数Android原生的API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的黑莓开发人员,我没有在Android的编程的经验。

I am blackberry developer and I don't have any experience in Android programming.

我想创建一个Android应用程序,这将有web视图/嵌入式浏览器。我将加载一些网页,在浏览器中嵌入一些JavaScript代码。将有哪些会调用JavaScript函数在页面上的某些按钮。有些功能需要访问本机API(如照相机API)。是否可以调用本地的API从JavaScript函数或访问应用程序的本地code?

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 ?

现在,这是可能的使用JavaScript扩展黑莓平台。我期待在Android的类似的东西。

Right now this is possible in blackberry platform using Javascript extension. I'm expecting something similar in Android.

感谢你。

任何人谁是寻找答案,我已经找到解决方案的基础上@dtanders回答。 看一下这个: <一href="http://developer.android.com/guide/webapps/webview.html#BindingJavaScript">http://developer.android.com/guide/webapps/webview.html#BindingJavaScript

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

推荐答案

使用<一个href="http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface%28java.lang.Object,%20java.lang.String%29">http://developer.android.com/reference/android/webkit/WebView.html#addJavascriptInterface(java.lang.Object, java.lang.String中)公开Java接口的JavaScript中的web视图运行

Use 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

这篇关于从调用嵌入的WebView的JavaScript函数Android原生的API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆