# myAgentWeb
**Repository Path**: welldonexing/myAgentWeb
## Basic Information
- **Project Name**: myAgentWeb
- **Description**: No description available
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-06
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
agentweb 修改备用
## 引入
* Gradle
```
implementation 'com.just.agentweb:agentweb:4.1.3' // (必选)
implementation 'com.just.agentweb:filechooser:4.1.3'// (可选)
implementation 'com.download.library:Downloader:4.1.3'// (可选)
```
## 相关
* [AgentWebX5](https://github.com/Justson/AgentWebX5)
* [一个炫酷的 WebView 进度条](https://github.com/Justson/CoolIndicator)
* [Downloader 一个轻量的文件下载器](https://github.com/Justson/Downloader)
## 使用
#### 基础用法
```java
mAgentWeb = AgentWeb.with(this)
.setAgentWebParent((LinearLayout) view, new LinearLayout.LayoutParams(-1, -1))
.useDefaultIndicator()
.createAgentWeb()
.ready()
.go("http://www.jd.com");
```
* #### 调用 Javascript 方法拼接太麻烦 ? 请看 。
```javascript
function callByAndroid(){
console.log("callByAndroid")
}
mAgentWeb.getJsAccessEntrace().quickCallJs("callByAndroid");
```
* #### Javascript 调 Java ?
```java
mAgentWeb.getJsInterfaceHolder().addJavaObject("android",new AndroidInterface(mAgentWeb,this));
window.android.callAndroid();
```
* #### 事件处理
```java
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (mAgentWeb.handleKeyEvent(keyCode, event)) {
return true;
}
return super.onKeyDown(keyCode, event);
}
```
* #### 跟随 Activity Or Fragment 生命周期 , 释放 CPU 更省电 。
```java
@Override
protected void onPause() {
mAgentWeb.getWebLifeCycle().onPause();
super.onPause();
}
@Override
protected void onResume() {
mAgentWeb.getWebLifeCycle().onResume();
super.onResume();
}
@Override
public void onDestroyView() {
mAgentWeb.getWebLifeCycle().onDestroy();
super.onDestroyView();
}
```
* #### 全屏视频播放
```
android:hardwareAccelerated="true"
android:configChanges="orientation|screenSize"
```
* #### 定位
```
```
* #### WebChromeClient 与 WebViewClient
```java
AgentWeb.with(this)
.setAgentWebParent(mLinearLayout,new LinearLayout.LayoutParams(-1,-1) )
.useDefaultIndicator()
.setReceivedTitleCallback(mCallback)
.setWebChromeClient(mWebChromeClient)
.setWebViewClient(mWebViewClient)
.setSecutityType(AgentWeb.SecurityType.strict)
.createAgentWeb()
.ready()
.go(getUrl());
private WebViewClient mWebViewClient=new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap favicon) {
//do you work
}
};
private WebChromeClient mWebChromeClient=new WebChromeClient(){
@Override
public void onProgressChanged(WebView view, int newProgress) {
//do you work
}
};
```
* #### 返回上一页
```java
if (!mAgentWeb.back()){
AgentWebFragment.this.getActivity().finish();
}
```
* #### 获取 WebView
```java
mAgentWeb.getWebCreator().getWebView();
```
* #### 查看 Cookies
```java
String cookies=AgentWebConfig.getCookiesByUrl(targetUrl);
```
* #### 同步 Cookie
```java
AgentWebConfig.syncCookie("http://www.jd.com","ID=XXXX");
```
* #### MiddlewareWebChromeBase 支持多个 WebChromeClient
```java
//略,请查看 Sample
```
* #### MiddlewareWebClientBase 支持多个 WebViewClient
```java
//略,请查看 Sample
```
* #### 清空缓存
```java
AgentWebConfig.clearDiskCache(this.getContext());
```
* #### 权限拦截
```java
protected PermissionInterceptor mPermissionInterceptor = new PermissionInterceptor() {
@Override
public boolean intercept(String url, String[] permissions, String action) {
Log.i(TAG, "url:" + url + " permission:" + permissions + " action:" + action);
return false;
}
};
```
* #### AgentWeb 完整用法
```java
//略,请查看 Sample
```
* #### AgentWeb 所需要的权限(在你工程中根据需求选择加入权限)
```
```
* #### AgentWeb 所依赖的库
```
compile "com.android.support:design:${SUPPORT_LIB_VERSION}" // (3.0.0开始该库可选)
compile "com.android.support:support-v4:${SUPPORT_LIB_VERSION}"
SUPPORT_LIB_VERSION=27.0.2(该值会更新)
```
## 混淆
如果你的项目需要加入混淆 , 请加入如下配置
```java
-keep class com.just.agentweb.** {
*;
}
-dontwarn com.just.agentweb.**
```
Java 注入类不要混淆 , 例如 sample 里面的 AndroidInterface 类 , 需要 Keep 。
```java
-keepclassmembers class com.just.agentweb.sample.common.AndroidInterface{ *; }
```
## 注意事项
* 支付宝使用需要引入支付宝SDK ,并在项目中依赖 , 微信支付不需要做任何操作。
* AgentWeb 内部使用了 `AlertDialog` 需要依赖 `AppCompat` 主题 。
* `setAgentWebParent` 不支持 `ConstraintLayout` 。
* `mAgentWeb.getWebLifeCycle().onPause();`会暂停应用内所有`WebView` 。
* `minSdkVersion` 低于等于16以下自定义`WebView`请注意与 `JS` 之间通信安全。
* AgentWeb v3.0.0以上版本更新了包名,混淆的朋友们,请更新你的混淆配置。
* 多进程无法取消下载,[解决方案](https://github.com/Justson/AgentWeb/issues/294)。
## 常见问题
#### 修改 AgentWeb 默认的背景色
```java
FrameLayout frameLayout = mAgentWeb.getWebCreator().getWebParentLayout();
frameLayout.setBackgroundColor(Color.BLACK);
```