Justson / AgentWeb
- пятница, 16 июня 2017 г. в 03:11:44
Java
🔥 AgentWeb 是基于 Android WebView 一个功能完善小型浏览器库 。 使用很方便 , 集成进你应用 ,只需几行代码 。
AgentWeb 是一个高度封装的 Android WebView ,简单易用 , 带有进度条 、 支持文件上传 、 下载 、 简化 Javascript 通信 、 链式调用 、 加强 Web 安全的库 。让你几行代码集成一个小型浏览器在你的应用 。更多使用请参照上面的 sample 。 下载 AgentWeb
WebView 可谓是每个应用必备的一个控件了 ,但是谈起它的使用 ,让很多人都不是那么喜欢它 ,比如说每个 Web 页面都需要各种一大推的 setting ,好一点的可能封装成一个 BaseWebActivity 和 BaseWebFragment ,但是重复的代码总是让有洁癖的程序员不舒服 ,而且 WebView 本身功能也不是很完善 , AgentWeb 就泥补了这些空缺 。
Web | 文件下载 | 文件上传 | Js 通信 | 断点续传 | 使用简易度 | 进度条 | 线程安全 | 全屏视频 |
---|---|---|---|---|---|---|---|---|
WebView | 不支持 | 不支持 | 支持 | 不支持 | 麻烦 | 没有 | 不安全 | 不支持 |
AgentWeb | 支持 | 支持 | 更简洁 | 支持 | 简洁 | 有 | 安全 | 支持 |
Gradle
compile 'com.just.agentweb:agentweb:1.2.1'
Maven
<dependency>
<groupId>com.just.agentweb</groupId>
<artifactId>agentweb</artifactId>
<version>1.2.1</version>
<type>pom</type>
</dependency>
mAgentWeb = AgentWeb.with(this)//传入Activity
.setAgentWebParent(mLinearLayout, new LinearLayout.LayoutParams(-1, -1))//传入AgentWeb 的父控件 ,如果父控件为 RelativeLayout , 那么第二参数需要传入 RelativeLayout.LayoutParams
.useDefaultIndicator()// 使用默认进度条
.defaultProgressBarColor() // 使用默认进度条颜色
.setReceivedTitleCallback(mCallback) //设置 Web 页面的 title 回调
.createAgentWeb()//
.ready()
.go("http://www.jd.com");
里面没有一句 Setting , 甚至连 WebChromeClient 都不用配置就有进度条 。
//Javascript 方法
function callByAndroid(){
console.log("callByAndroid")
}
//Android 端
mAgentWeb.getJsEntraceAccess().quickCallJs("callByAndroid");
//结果
consoleMessage:callByAndroid lineNumber:27
@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);
}
<!--如果你的应用需要用到视频 , 那么请你在使用 AgentWeb 的 Activity 对应的清单文件里加入如下配置-->
android:hardwareAccelerated="true"
android:configChanges="orientation|screenSize"
<!--AgentWeb 是默认启动定位的 , 请在你的 AndroidManifest 文件里面加入如下权限 。-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
如果你的项目需要加入混淆 , 请加入如下配置
-keep class com.just.library.** {
*;
}
-dontwarn com.just.library.**
Java 注入类不要混淆 , 例如 App 里面的 AndroidInterface 类 , 需要 Keep 。
-keepclassmembers class com.just.library.agentweb.AndroidInterface{ *; }
一个位于深圳的 Android 开发者 , 如果你有更好的工作机会提供给我 , 请联系 Email : xiaozhongcen@gmail.com
AgentWeb 是一个把 WebView 完全代理出来 , 脱离 Activity 、 Fragment xml 布局 , 独立的 Android Web 库 。
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.