Agentweb
AgentWeb is a powerful library based on Android WebView.
Under Apache License 2.0
By Justson
AgentWeb is a powerful library based on Android WebView.
Under Apache License 2.0
By Justson
AgentWeb 介绍
AgentWeb 是一个基于的 Android WebView ,极度容易使用以及功能强大的库,提供了 Android WebView 一系列的问题解决方案 ,并且轻量和极度灵活,详细使用请参照上面的 Sample 。
groovy
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
groovy
implementation 'com.github.Justson.AgentWeb:agentweb-core:v4.1.9' // (必选)
implementation 'com.github.Justson.AgentWeb:agentweb-filechooser:v4.1.9' // (可选)
implementation 'com.github.Justson:Downloader:v4.1.9' // (可选)
```groovy
implementation 'com.github.Justson.AgentWeb:agentweb-core:v4.1.9-androidx' // (必选)
implementation 'com.github.Justson.AgentWeb:agentweb-filechooser:v4.1.9-androidx' // (可选)
implementation 'com.github.Justson:Downloader:v4.1.9-androidx' // (可选)
```
```java
mAgentWeb = AgentWeb.with(this)
.setAgentWebParent((LinearLayout) view, new LinearLayout.LayoutParams(-1, -1))
.useDefaultIndicator()
.createAgentWeb()
.ready()
.go("http://www.jd.com");
```
java
function callByAndroid(){
console.log("callByAndroid")
}
mAgentWeb.getJsAccessEntrace().quickCallJs("callByAndroid");
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);
}
```
```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"
```
```
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();
}
java
mAgentWeb.getWebCreator().getWebView();
java
String cookies=AgentWebConfig.getCookiesByUrl(targetUrl);
java
AgentWebConfig.syncCookie("http://www.jd.com","ID=XXXX");
java
//略,请查看 Sample
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;
}
};
```
java
//略,请查看 Sample
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CAMERA"></uses-permission>
<uses-permission android:name="android.permission.REQUEST_INSTALL_PACKAGES"></uses-permission>
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{ *; }
AlertDialog
需要依赖 AppCompat
主题 。 setAgentWebParent
不支持 ConstraintLayout
。mAgentWeb.getWebLifeCycle().onPause();
会暂停应用内所有WebView
。minSdkVersion
低于等于16以下自定义WebView
请注意与 JS
之间通信安全。java
FrameLayout frameLayout = mAgentWeb.getWebCreator().getWebParentLayout();
frameLayout.setBackgroundColor(Color.BLACK);
Sample
(推荐,详细) SafeWebView
WebView 参考文献
一个位于深圳的 Android 开发者 , 如果你有问题 , 请联系 Email : [email protected]
如果你喜欢了 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.
```