Some time ago, my company's project involved communication between WebView and JS. So I checked some information on the Internet and studied the problem.
1. Interaction between WebView and JS
1. JS calls local methods
This function is easy to implement. You can directly call the WebView method to add an interface. However, you must start the interaction first.
/
password and clicks the authorization button, the activity will not jump to the authorizeactivity, only the browser that comes with Android is correct. In fact, this is a serious problem. Most users will use third-party browsers such as UC, which leads to abnormal authentication.
I recently found a good idea when I tried oauth authentication on the iPhone, that is, do not use a browser with the system and embed a
With the performance of the mobile phone, as well as the popularity of iOS and Android two platforms, more apps are going to be developed in the two-platform app, and in some cases, for faster development, we'll use hybird to develop, This time we need to use WebView and make some configuration ourselves. Android's WebView has a different webkit version of the ke
Use WebView analog login on Cnblogs's Android client, which will require the user's username and password to be uploaded to the WebView and then submitted, which tests all the normal mx3 Flyme3 and flyme4. However, on my htcG12 (MIUI4), and Samsung Note2 on the error.The error code is:
The code is as follows
Copy Code
Public void Log
focus is on the addjavascriptinterface (Object OBJ, string interfacename) method. This method binds a Java object to a JavaScript Object. The JavaScript Object Name Is interfacename and the scope is global. After webview initialization, you can directly access the bound Java object through javascript: window. demo on
);12Webview.getsettings (). Setsupportzoom (True);Click the link in the current browser response, not the new Android system browser should link in the ring13Webview.setwebchromeclient (New Webchromeclient ()14{15public void onprogresschanged (WebView view, int progress)16{17Activity.settitle ("Loading ...");18Activity.setprogress (Progress * 100);19if (progress = = 100) {20Activity.settitle (R.string.app_n
("'"). Append (Params[i].tostring ()). Append ("'");if (I Result.append (",");}}Result.append (")");String jsstr = result.tostring ();Webview.loadurl (JSSTR);}}
The Java object to be used for JS invocationClass myjavascriptinterface{Myjavascriptinterface (WebView WV, Handler h) {This.thewebview = WV;This.handler = h;}WebView Thewebview;Handler Handler;//Java method to be used for JS invocation@Javascript
My recent project needs to join the document Cloud returned directly to the IFRAME tag based on the data back in the background, but Android wanted to load it with WebView, and there were all sorts of problems in the middle. So just sort out the code and make a note for yourself and hope it will help you.
Directly on key code:
This is the interface returned by the IFRAME tag (this is a dynamic PPT text, the
Android WebKit
WebKit is an Open-source browser typesetting and rendering engine that includes WebCore and JavaScriptCore. WebKit has numerous implementations (Qt, GTK, windows, chromium, Android, etc).
The Android 4.0 platform's Web engine framework uses the Webcore,javascript engine in WebKit to use Google's V8 engi
activity: Mwebview.goback ();WebView WebView;/** called when the activity is first created. */@Overridepublic void OnCreate (Bundle savedinstancestate) {Super.oncreate (savedinstancestate);Setcontentview (R.layout.main);Get WebView ObjectWebView = (webview) Findviewbyid (R.id.webview);
Android provides a WebView control that allows us to embed a browser in our own application to easily display a wide variety of web pages. Let's learn the simple usage below. Create a new Webviewtest project, and then modify the code in the Activity_main.xml as follows:Then modify the code in the mainactivity as follows: Package Com.jack.webviewtest;import Android.os.bundle;import Android.app.activity;im
1. Open the Web page directly from the URL Web site display content: Loadurl ()
First, write a WebView control in the layout
relativelayout xmlns:android="Http://schemas.android.com/apk/res/android" xmlns:tools= "http://schemas.android.com/tools"android:layout_width="Match_ Parent "android:layout_height="match_parent "tools:context=" Com.example.ygd.jreduch09.WebViewActivity ">
Android provides a WebView object for web browsing.1, want to use WebView, first should give permission:internet.2. WebView Loading HTML Document3. Call Android object in WebView using javascr
Android cannot actively call the test results of recent projects.
Webview. loadUrl ("javascript:" + callbackFunction + "('" + data + "')"); this method transmits data of the jsonobject type to js, because js gets a string object.
At the same time, js actively calls the android object method, and
content, you must use JS to call JAVA code.Class Handler {@ JavascriptInterface // This is required for api level17. If this parameter is not added, no error is reported, that is, no call is required. It took one and a half hours to complete. Public void show (String data) {Log. d ("Google Login", "handler, show, data =" + data); System. out. println ("data =" + data) ;}} webview. getSettings (). setJavaScriptEnabled (true); // sets the
This example for you to share the Android WebView use summary for your reference, the specific contents are as follows
# using overloaded URL to realize Java and JS interaction
In Android, the common Java and JS interaction is implemented through function Addjavascriptinterface to add the callback proxy class used in JS.Although this method is convenient, but
These days with the NEXUS5 4.4.4 system to do a simple mobile phone device number to get, and then invoke JavaScript display in the Web page function, has done more than n similar programs, the results of the program a run any problems are out, hehe
[Info:console (1)] "Uncaught Referenceerror:is not define
I/chromium (490): [Info:console (1)] "uncaught syntaxerror:unexpected token
[Android] Web console:unca
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.