Background: Android API provides WebView component to realize HTML rendering. Now HTML5, CSS3, JS related development technology, and data exchange format json/XML. Skills of Web development engineers. In order to reduce excessive dependence on Android, some HTML is usually embedded in native Android. In this way, js data interaction is inevitable. We create a simple layout with only one webview control
We find this webView and load the local main.html, where main.html is stored in the assets root directory of the project file.
1.js calls Android method If you are careful, you should notice that there is a JSObject class above. Yes, this is the entry point, so that the front-end js can call the methods written on our Android side. The "aikaifa" can be understood as a mark, which can be changed to whatever you like. Let's take a look at the JSObject class:
This class defines the goBack method, which can be called by injecting JS. If you want to call the goBack method in js, you can call it like this: aikaifa.goBack(). In this way, the front end can easily call our Android methods. 2.Android calls JS method Since js can call our methods, we also call js methods For example, we want to call the getName method in js. We can write it like this.
The getName method is a method in js, and we can call the getTestJS method where needed. In this way, the interaction between WebView and js is roughly completed. [This article is an original article by 51CTO columnist "Hong Shengpeng". Please contact the original author for reprinting.] Click here to read more articles by this author |
<<: iOS AFNetworking framework HTTPS request configuration
KOL is a hot new star that has emerged in recent ...
We give so much meaning to our nails! "My na...
NetEase Yanxuan is a boutique shopping e-commerce...
This article is produced by "Science Facts&q...
In today's society, business operations canno...
Apple recently announced on its official website ...
Some time ago, Google announced a brand upgrade f...
In addition to giants such as WeChat, Taobao, and...
According to the latest data from AutoForecast So...
At 0:28 on December 22, 2017 (Friday), we will us...
On December 15, the Natural Resources Comprehensi...
The 2025 Zhongguancun Forum Annual Meeting offici...
Entering 2019, overseas traffic costs are still o...
In 1895, Roentgen discovered X-rays, but what exa...
Not long ago, a colleague of mine bought another i...