问题标签 [android-jsinterface]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
206 浏览

java - Why is Android JSInterface so slow?

I have a javascript calling a javascript interface many times (around 500 times sometimes), updating the page's UI from it. It sends a couple strings, and casts String result to string: ""+window.INTERFACENAME.function(...).

Without calling the function, it takes 43ms, but takes 6 or 7 seconds with the JSInterface call. Why is the JSInterface so slow?

0 投票
0 回答
1495 浏览

android - Using WebView for multi-page login to website and fetch data

I'm building an Android app as a mobile client for a website that does not (and will not) have it's own UI for mobile browsers. My chosen architecture uses a hidden WebView which I initialise (loadURL) with the login page, and then I load JavaScript to populate the login pages (there are two) with the user's name, password and other credentials. Once logged in, I'll navigate to a new URL and then use a JavaScriptInterface to extract sections of HTML from the pages for parsing and use in my app, following the tutorial here: http://lexandera.com/2009/01/extracting-html-from-a-webview/

My Webview has a JavaScriptInterface class with 3 methods:

and

This scripting of the website is done in my WebView's WebViewClient.onPageFinished method, which checks the current URL and then executes the next step in the login/browsing process. i.e.

My problem is that when running the app, the onPageFinished callback doesn't always get called for every page, so the process stalls. But when I debug in Eclipse/ADT, and single-step through the code, it seems to work perfectly every time and all the page navigation works and the JavascriptInterface methods get called.

Is there some thread or race condition issue to be considered here? Is there a better -more reliable and/or easier - way to architect this?

0 投票
1 回答
338 浏览

javascript - Ajax 请求支持 Android

android(4.0 +) 是否支持 Ajax 请求。如果是这样,请提供一些帮助。我需要使用 javascript 从 android WebView 调用 ajax。

0 投票
0 回答
103 浏览

android - 检查在 android 应用程序中加载的 html 元素

我在我的 Android 应用程序中使用 webview 渲染一个 html 文件。我还使用一些 javascript 函数来处理内容。有什么方法可以检查 html 内容(例如浏览器中的检查元素)请帮助,在此先感谢。

0 投票
0 回答
3976 浏览

javascript - 如何使用 webview.loadURL 从 javascript (Android) 获取变量

我会尽量把这点说清楚。我通常不擅长提出明确的问题,因此在此先感谢您阅读本文并发表任何建议。

我正在编写一个需要用户位置的简单 android 应用程序。我正在使用 webview 以及 HTML navigator.geolocation.getCurrentPosition 功能来跟踪用户。

我遇到的问题是将 HTML 文件中收集的坐标输入到我的 android/java 应用程序中。我在我的 webview 中使用 javascriptInterface 在两者之间进行通信。

这是我在 java 代码中对 webview 的声明。

这是 WebAppInterface 代码

最后但同样重要的是,这是我的 HTML 代码

截至目前,每次我想收集用户的坐标时,我都在使用以下代码行

这工作正常,直到调用 storePosition 函数。我认为这与我没有专门从 loadURL 调用 storePosition 函数有关,所以我尝试了

哪个有效。但是!!...我没有从 navigator.geolocation.getCurrentPosition 收集到的位置来发送到函数 storedPosition,所以显然没有任何反应。我在网上到处搜索解决方案,我得出的结论是我根本不明白 webview.LoadURL 函数是如何工作的。我需要获取存储在我的 android 应用程序中的坐标!

再次感谢您的时间和建议。

0 投票
1 回答
441 浏览

java - Android JavaScript Bridge - 触发事件

可能是一个简单的问题,我可以从 JavaScript 调用本机函数,例如:

Android.setVolume(0.7)

但是,我不知道如何触发(来自Android/Java),或处理不是由用户交互引起的事件(JS),例如,当用户的网络状态发生变化时提醒JS,电池电量低于某个点等等

非常感谢任何帮助。

0 投票
1 回答
916 浏览

android - videojs addEvent在android webview中不起作用

我正在使用 video.js 实现一个 youtube 视频播放器,我在 js 中动态传递 url,并让 video.js 播放视频。我想做的是让js在视频结束后通知android端,所以我添加了end事件来调用android方法。但它不起作用,有人知道这里有什么问题吗?

我在android端实现了一个jsinterface“AndroidFunction”

安卓端:

在js端,我实现了一个callAndroid函数来调用android JsInterface "AndroidFunction",并使用addEvent("ended", callAndroid)调用该函数

js端:

0 投票
4 回答
18012 浏览

android - 有时会抛出未捕获的错误:Android 上 NPObject 上的错误调用方法

我在使用 Android 中的 Webview 时遇到问题,它是 JavascriptInterfaces。

我将一个字符串传递给 JavascriptInterface。在调试它时,我在我的 Android 应用程序中收到了正确的字符串。问题:有时我得到一个未捕获的错误:在 NPObject 上调用方法时出错。

有人知道为什么吗?

Java中的接口:

Fragment内的onCreateView-Method中的初始化:

在Javascript中调用:

0 投票
1 回答
610 浏览

android - 通过 JsInterface 更改活动

祝你平安。

我正在为 Web 视图应用程序工作,并希望通过 JavaScript 更改活动。

首先,我为我的 WebView 添加了一个 JavascriptInterface:

这是课程:

当 JavaScript 调用 android.changeVisibility() 我的应用程序崩溃。

wv 在活动类中设置

我可以通过 JavaScript 更改活动中的任何其他视图(例如 Buttons 和 EditTexts)吗?

对不起,我的英语不好。

更新:LogCat

0 投票
3 回答
2441 浏览

android - 将 Json 数据保存到 ArrayList

我想从下面的 json 格式数据中有效地读取每个元素并将每个 json 元素存储在一个数组列表中