AgentWeb is an Android WebView based, extremely easy to use and powerful library. Please refer to Sample above for detailed usage.
AgentWeb Sample shows AgentWeb library powerful features, detailed link, please click the download experience
-
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>
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");
// Javascript method
Function callByAndroid () {
Console.log ("callByAndroid")
}
// Android end
MAgentWeb.getJsEntraceAccess (). QuickCallJs ("callByAndroid");
//onResult
ConsoleMessage: callByAndroid lineNumber: 27
// 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
@Override
Public boolean onKeyDown (int keyCode, KeyEvent event) {
If (mAgentWeb.handleKeyEvent (keyCode, event)) {
Return true;
}
Return super.onKeyDown (keyCode, event);
}
@Override
Protected void onPause () {
MAgentWeb.getWebLifeCycle (). OnPause ();
Super.onPause ();
}
@Override
Protected void onResume () {
MAgentWeb.getWebLifeCycle (). OnResume ();
Super.onResume ();
}
@Override
Protected void onActivityResult (int requestCode, int resultCode, Intent data) {
MAgentWeb.uploadFileResult (requestCode, resultCode, data);
Super.onActivityResult (requestCode, resultCode, data);
}
<! - 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"
<! - 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" />
// 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
}
};
WebView mWebView = mAgentWeb.getWebCreator (). Get ();
AgentWebConfig.syncCookies ("http://www.jd.com", "ID = XXXX")
// Slightly, please see Sample
// Slightly, please see Sample
String cookies = AgentWebConfig.getCookiesByUrl (targetUrl);
mAgentWeb = AgentWeb.with (this) //
.setAgentWebParent ((LinearLayout) view, new LinearLayout.LayoutParams (-1, -1)) // The AgentWeb parent passed in.
.setIndicatorColorWithHeight (-1, 2) / / Set the color and height of the onProgress bar, -1 is the default value, the height is 2, the unit is dp.
.setAgentWebWebSettings (getSettings ()) // Set AgentWebSettings.
.setWebViewClient (mWebViewClient) // WebViewClient, same as WebView, but do not get WebView calling setWebViewClient (xx) method, which will override AgentWeb DefaultWebClient and the corresponding middleware will also fail.
.setWebChromeClient (mWebChromeClient) // WebChromeClient
.setPermissionInterceptor (mPermissionInterceptor) / / permission to intercept 2.0.0 join.
.setReceivedTitleCallback (mCallback) // Title callback.
. SetSecurityType (AgentWeb.SecurityType.strict) / / strict mode Android 4.2.2 The following will give up the injection of the object, use AgentWebView did not affect.
.addDownLoadResultListener (mDownloadListener) // Download callback
.setAgentWebUIController (new UIController (getActivity ())) // Custom UI AgentWeb3.0.0 join.
.setMainFrameErrorView (R.layout.agentweb_error_page, -1) / / Parameter 1 is the layout of the onResult display, parameter 2 Click refresh control ID -1 Click to refresh the entire layout Click AgentWeb 3.0.0 to join.
.useMiddleWareWebChrome (getMiddleWareWebChrome ()) // Set up WebChromeClient middleware, support multiple WebChromeClient, AgentWeb 3.0.0 join.
.useMiddleWareWebClient (getMiddleWareWebClient ()) / / Set WebViewClient middleware, support multiple WebViewClient, AgentWeb 3.0.0 join.
. OpenParallelDownload () / / open parallel download, the default serial download.
.setNotifyIcon (R.mipmap.download) // Download notification icon.
.setOpenOtherPageWays (DefaultWebClient.OpenOtherPageWays.ASK) / / open other pages, the pop-up query users to other applications AgentWeb 3.0.0 to join.
.interceptUnkownScheme () / / Interception Scheme AgentWeb 3.0.0 can not find the relevant page to join.
.createAgentWeb () // Create AgentWeb.
.ready () / / Set WebSettings.
.go (getUrl ()); // WebView Load and display the URL page.
- 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
.
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 {*;}
- 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 .
- Welcome Issues
An Android developer located in Shenzhen, if you have a better job offer available to me, please contact Email: xiaozhongcen@gmail.com
If you like the design of AgentWeb, you can invite the author to have a cup of coffee.
AgentWeb is a WebView completely out of the Act, from the Activity, Fragment xml layout, independent of the Android Web library.
Finally, if the library is helpful to you, I may be grateful to the top right corner of my support, thanks! Of course, I prefer you to become a contributor to Fork PR. AgentWeb
Copyright (C) Justson(https://github.com/Justson/AgentWeb)
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.