AgentWeb
AgentWeb is a powerful library based on Android WebView.
AgentWeb is an Android WebView based, extremely easy to use and powerful library. Please refer to Sample above for detailed usage.
AgentWeb Sample Download
AgentWeb Sample shows AgentWeb library powerful features, detailed link, please click the download experience
download
-
Gradle
compile 'com.just.agentweb:agentweb:4.0.2' compile 'com.just.agentweb:download:4.0.2' compile 'com.just.agentweb:filechooser:4.0.2'
-
Maven
<dependency> <groupId>com.just.agentweb</groupId> <artifactId>agentweb</artifactId> <version>4.0.2</version> <type>pom</type> </dependency>
use
Common use
mAgentWeb = AgentWeb.with(this)//传入Activity or Fragment
.setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))//Incoming AgentWeb parent control, if the parent control is RelativeLayout, then the second parameter needs to be passed RelativeLayout.LayoutParams, the first parameter and the second parameter should correspond.
.useDefaultIndicator()// use the default onProgress bar
.defaultProgressBarColor() // Use default onProgress bar color
.setReceivedTitleCallback(mCallback) //Set the Web page title callback
.createAgentWeb()//
.ready()
.go("http://www.jd.com");
renderings
-
call Javascript method stitching too much trouble? Please see.
// Javascript method
Function callByAndroid () {
Console.log ("callByAndroid")
}
// Android end
MAgentWeb.getJsEntraceAccess (). QuickCallJs ("callByAndroid");
//onResult
ConsoleMessage: callByAndroid lineNumber: 27
-
Javascript call Java
// Android side, AndroidInterface is an injection class, which has a no parameter method: callAndroid
AddjavaObject ("android", new AndroidInterface (mAgentWeb, this));
/ / In Js will be able to pass
Window.android.callAndroid () / / call the Java layer AndroidInterface class callAndroid method
-
event handling
@Override
Public boolean onKeyDown (int keyCode, KeyEvent event) {
If (mAgentWeb.handleKeyEvent (keyCode, event)) {
Return true;
}
Return super.onKeyDown (keyCode, event);
}
-
Follow the Activity Or Fragment life cycle, the release of CPU more power.
@Override
Protected void onPause () {
MAgentWeb.getWebLifeCycle (). OnPause ();
Super.onPause ();
}
@Override
Protected void onResume () {
MAgentWeb.getWebLifeCycle (). OnResume ();
Super.onResume ();
}
-
File upload processing
-
full screen video playback
<! - If your application needs to use the video, then please use the AgentWeb Activity corresponding to the list file to add the following configuration ->
Android: hardwareAccelerated = "true"
Android: configChanges = "orientation | screenSize"
-
positioning
<! - AgentWeb is the default boot location, please add the following permissions in your AndroidManifest file. ->
<Uses-permission android: name = "android.permission.ACCESS_FINE_LOCATION" />
<Uses-permission android: name = "android.permission.ACCESS_COARSE_LOCATION" />
-
WebChromeClient Or WebViewClient handles business logic
// AgentWeb maintains the use of WebView,
MAgentWeb = AgentWeb.with (this) //
.setAgentWebParent (mLinearLayout, new LinearLayout.LayoutParams (-1, -1)) //
.useDefaultIndicator () //
.defaultProgressBarColor ()
.setReceivedTitleCallback (mCallback)
.setWebChromeClient (mWebChromeClient)
.setWebViewClient (mWebViewClient)
.setSecutityType (AgentWeb.SecurityType.strict)
.createAgentWeb () //
.ready ()
.go (getUrl ());
// WebViewClient
Private WebViewClient mWebViewClient = new WebViewClient () {
@Override
Public void onPageStarted (WebView view, String url, Bitmap favicon) {
// do you work
}
};
// WebChromeClient
Private WebChromeClient mWebChromeClient = new WebChromeClient () {
@Override
Public void onProgressChanged (WebView view, int newProgress) {
// do you work
}
};
-
Get WebView
WebView mWebView = mAgentWeb.getWebCreator (). Get ();
-
Sync cookies
AgentWebConfig.syncCookies ("http://www.jd.com", "ID = XXXX")
-
MiddleWareWebChromeBase supports multiple WebChromeClients
-
MiddleWareWebClientBase supports multiple WebViewClient
-
View Cookies
String cookies = AgentWebConfig.getCookiesByUrl (targetUrl);
-
AgentWeb Complete use
Precautions
- Alipay need to use the introduction of Alipay SDK, and dependent on the project, WeChat payment do not need to do any operation.
- AgentWeb‘s internal use of AlertDialog depends on the
AppCompat
theme. setAgentWebParent
does not supportConstraintLayout
.mAgentWeb.getWebLifeCycle (). onPause ();
Will pause allWebView
in the application.minSdkVersion
16 or less CustomizeWebView
Please be aware of communication safety withJS
.
ProGuard rules
If your project needs to be proguard , please add the following configuration
-keep class com.just.agentweb.** {
*;
}
-dontwarn com.just.agentweb.**
Java injection class do not proguard, such as sample inside the AndroidInterface class, need Keep.
-keepclassmembers class com.just.library.agentweb.AndroidInterface {*;}
update log
- v_3.0.0 update
- Add MiddlewareWebChromeBase middleware, support multiple WebChromeClient.
- Add
MiddleWareWebClientBase
middleware, support multipleWebViewClient
. - Added the default onResult page, and supports custom onResult page.
- Join
AgentWebUIController
, unified control UI. - Support for blocking unknown pages.
- Support to tune other applications.
- v_2.0.1 update
- Support for parallel download, repair # 114 # 109.
- v_2.0.0 update
- Join dynamic rights.
- Take pictures.
- v_1.2.6 update
- Fixed Android 4.4 following layout disordered.
- v_1.2.5 Prompt message support configuration.
- Prompt message support configuration.
- v_1.2.4 update
- Support incoming IWebLayout, support pull-down rebound, pull-down refresh effect.
- v_1.2.3 update
- Added download onResult callback.
- v_1.2.2 update
- Fixed known bug.
- v_1.2.1 update
- Support tune Alipay, WeChat payment.
- v_1.2.0 update
- Full support for full screen video.
- v_1.1.2 update
- Improve the function .