Android and JavaScript interaction
SEP 20TH, 2014
Android provides a powerful WebView control for working with Web pages, and JavaScript is a very important script in Web pages. This article describes how to implement mutual invocation of Java code and JavaScript code. How to achieve
Java and JS to implement the interaction is very convenient. Typically, only the following steps are required. WebView open JavaScript Script execution WebView set up an interactive interface for JavaScript calls. The client and the Web end write the code that invokes the other. This example code
For ease of explanation, first paste out all code Java code lineos:false
1
2
3
4
5
6 7 8 9 (16) He ' is in the
same
A
43-A-I-M By the----
-
64 of the same
|
package Com.example.javajsinteractiondemo;
Import Android.annotation.SuppressLint;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.Menu;
Import Android.webkit.JavascriptInterface;
Import android.webkit.WebChromeClient;
Import android.webkit.WebSettings;
Import Android.webkit.WebView;
Import android.webkit.WebViewClient;
Import Android.widget.Toast; public class Mainactivity extends activity {private static final String LogTag = "mainactivity"; |