Android and JavaScript Interactive __java

Source: Internet
Author: User
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"; 
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.