Atitit. android webview h5 running environment summary, androidwebviewh5
Atitit. android webview h5 running environment Summary
1. Use of WebView 1
2. Js calls java1
3. Comparison between Js calls of java and swt 2
3.1. Swt is a BrowserFunction mechanism and is bound to custom method 2.
3.1.1. nativeswing implementation pre-bind a sendNSCommand method 2
4. code2
5. Webview code4
1. Use of WebView
2. Js calls java
BrowExt. play ();
WebView. addJavascriptInterface (new browExtObj (this), "browExt ");
WebView. loadUrl (url );
The implementation mode is to bind a browser object that can be customized
Author ::★(Attilax)> nickname: old wow's paw (full name: Attilax Akbar Al Rapanui Attila Akba Arla Panui) Chinese name: AI long, EMAIL: 1466519819@qq.com
Reprinted please indicate Source: http://www.cnblogs.com/attilax/
3. Js calls the comparison between java and swt 3.1. Swt is the BrowserFunction mechanism and is bound with a custom method.
New CallJavaPaa1 (browser, "sendNSCommand ");
BrowserFunction is a very interesting class. It can permanently bind a JavaScript method to Browser. Its constructor is BrowserFunction (browser: Browser, name: String), where browser represents the Browser object, name indicates the JavaScript method name bound to the Browser. After the BrowserFunction object is defined, any webpage displayed on the Browser can access the JavaScript method named name.
3.1.1. nativeswing implementation pre-bind a sendNSCommand Method
SendNSCommand ('play', video );
4. code
Package com. example. atiplat_vodcp;
Import java. io. File;
Import java. io. PrintWriter;
Import java. io. StringWriter;
Import java.net. URLEncoder;
Import android. content. Intent;
Import android.net. Uri;
Import android. OS. Environment;
Import android. util. Log;
Import android. webkit. JavascriptInterface;
Import android. widget. Toast;
Public class browExtObj {
Public static String getTrace (Throwable t ){
StringWriter stringWriter = new StringWriter ();
PrintWriter writer = new PrintWriter (stringWriter );
T. printStackTrace (writer );
StringBuffer buffer = stringWriter. getBuffer ();
Return buffer. toString ();
}
MainActivity mainActivity;
Public browExtObj (MainActivity mainActivity2 ){
MainActivity = mainActivity2;
}
@ JavascriptInterface // sdk17 or a later version with the annotation solu click btn ma fein ..
Public void play (){
Try {
String mv = "smb: // 192.168.2.106/e/non-Blu-ray/startup/secret program .mp4 ";
Log. v (": mv in html", mv );
Toast. makeText (mainActivity,
"Play in html, mv:" + new File (mv). exists (),
Toast. LENGTH_LONG). show ();
String mv2 = Environment. getExternalStorageDirectory (). getPath ()
+ "/Test_Movie.m4v ";
Mv = "http: // 127.0.0.1: 7788 /? File = "+ URLEncoder. encode (mv," UTF-8 ");
// Log. v ("URI html:", uri. toString ());
Uri uri = Uri. parse (mv );
// Call the player that comes with the System
Intent intent = new Intent (Intent. ACTION_VIEW );
Log. v ("URI html:", uri. toString ());
// Intent. setData (uri );
Intent. setDataAndType (uri, "video /*");
MainActivity. startActivity (intent );
System. out. println ("-- form_load finish ");
} Catch (Throwable e ){
Log. I ("::::::::::::::: exp", getTrace (e ));
}
}
5. Webview code
WebView webView;
Public static String getTrace (Throwable t ){
StringWriter stringWriter = new StringWriter ();
PrintWriter writer = new PrintWriter (stringWriter );
T. printStackTrace (writer );
StringBuffer buffer = stringWriter. getBuffer ();
Return buffer. toString ();
}
@ SuppressLint ("SetJavaScriptEnabled ")
Public void form_load (){
Try {
String simple = pinystrap. getSimple ("Android prompt ");
New AlertDialog. Builder (this). setTitle (simple)
. SetMessage ("this is a prompt, please be sure"). show ();
WebView = (WebView) findViewById (R. id. webView1 );
// Set WebView attributes to execute Javascript scripts
WebView. getSettings (). setJavaScriptEnabled (true );
WebView. loadUrl ("http: // 139.196.164.150: 8080/lime/cmsWechat/list.html ");
} Catch (Throwable e ){
Log. I ("exp", getTrace (e ));
}
}
@ Override
Protected void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
//// Load the webpage to be displayed
// Webview. loadUrl ("http://www.51cto.com /");
//// Set the Web View
//
SetContentView (R. layout. activity_main );
Form_load ();
// SetContentView (webView );
}