{"id":15030271,"url":"https://github.com/youlookwhat/bywebview","last_synced_at":"2025-05-15T20:03:05.152Z","repository":{"id":44338334,"uuid":"73827854","full_name":"youlookwhat/ByWebView","owner":"youlookwhat","description":"🌏  WebView 全方面使用，JS交互、进度条、上传图片、错误页面、视频全屏播放、唤起原生App、获取网页源代码、被作为第三方浏览器打开、DeepLink、[腾讯x5使用示例]","archived":false,"fork":false,"pushed_at":"2024-03-15T10:18:29.000Z","size":11726,"stargazers_count":1544,"open_issues_count":7,"forks_count":300,"subscribers_count":43,"default_branch":"master","last_synced_at":"2025-04-08T01:38:10.240Z","etag":null,"topics":["android","android-webview","deeplink","tencent-x5","webview","x5"],"latest_commit_sha":null,"homepage":"https://youlookwhat.github.io/ByWebView","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/youlookwhat.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-15T15:34:54.000Z","updated_at":"2025-04-07T07:45:15.000Z","dependencies_parsed_at":"2024-02-28T04:23:49.557Z","dependency_job_id":"59e0c11f-ba12-4bdb-9e94-d7c57a188ff6","html_url":"https://github.com/youlookwhat/ByWebView","commit_stats":{"total_commits":206,"total_committers":3,"mean_commits":68.66666666666667,"dds":0.03398058252427183,"last_synced_commit":"8dd9d3c058efe172ff7c10f6155b1837563c4ae0"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youlookwhat%2FByWebView","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youlookwhat%2FByWebView/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youlookwhat%2FByWebView/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/youlookwhat%2FByWebView/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/youlookwhat","download_url":"https://codeload.github.com/youlookwhat/ByWebView/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254414493,"owners_count":22067271,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["android","android-webview","deeplink","tencent-x5","webview","x5"],"created_at":"2024-09-24T20:12:56.503Z","updated_at":"2025-05-15T20:03:04.274Z","avatar_url":"https://github.com/youlookwhat.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ByWebView\n[![JitPack][5]][6] [![API][7]][8] [![download][1]][2] \u003c!--[![version][3]][4] --\u003e\n\n\u003c!--![](https://img.shields.io/github/stars/youlookwhat/WebViewStudy.svg?style=flat-square) ![](https://img.shields.io/github/forks/youlookwhat/WebViewStudy.svg?style=flat-square) ![GitHub watchers](https://img.shields.io/github/watchers/youlookwhat/WebViewStudy.svg?style=flat-square\u0026label=Watch)\n--\u003e\n\n## Features\n\n - 基本配置使用(宽度自适应、返回网页上一层、显示网页标题等)\n - 唤起三方应用(拨打电话、发送短信、发送邮件等)\n - 上传图片(版本兼容)\n - 错误页面处理\n - 全屏播放网络视频\n - **与Js交互实例**\n - 优雅的进度条显示控件\n\n**Demo示例：**\n\n - DeepLink的基本使用\n - 被作为第三方浏览器打开\n - 与ToolBar联动，自定义WebView\n - **腾讯x5使用示例**\n\n## Document\n\n - [Android 关于WebView全方面的使用（项目应用篇）](http://www.jianshu.com/p/163d39e562f0)\n - [Android DeepLink介绍与使用](https://juejin.cn/post/6844903954149539848)\n - [Android 应用被作为第三方浏览器打开](https://www.jianshu.com/p/272bfb6c0779)\n - [Android WebView与JS交互实例](https://www.jianshu.com/p/97f52819a19d)\n - [一款Android WebView进度条显示控件，使其加载进度平滑过渡](https://github.com/youlookwhat/WebProgress)\n\n## Screenshots\n \n ![bywebview](https://github.com/youlookwhat/ByWebView/blob/master/art/bywebview.png?raw=true)\n\n## Download\n - [Demo示例下载][2]\n\n## 引用\n1. Add the JitPack repository to your build file\n\n ```java\nallprojects {\n\trepositories {\n\t\t...\n\t\tmaven { url 'https://jitpack.io' }\n\t}\n}\n ```\n2. Add the dependency:\n\n ```java\ndependencies {\n\timplementation 'com.github.youlookwhat:ByWebView:1.2.1'\n}\n\n ```\n\n## Use\n```java\nbyWebView = ByWebView\n        .with(this)\n        .setWebParent(container, new LinearLayout.LayoutParams(-1, -1))\n        .useWebProgress(ContextCompat.getColor(this, R.color.coloRed))\n        .loadUrl(mUrl);\n```\n\n### 与Js交互\n - 调用Js方法：\n\n```java\n// 无参数调用\nbyWebView.getLoadJsHolder().quickCallJs(\"javacalljs\");\n// 传递参数调用\nbyWebView.getLoadJsHolder().quickCallJs(\"javacalljswithargs\", \"android传入到网页里的数据，有参\");\n```\n - Js调用Java方法：\n\n```java\nByWebView.with(this)\n\t.addJavascriptInterface(\"injectedObject\", new MyJavascriptInterface(this))\n\t.loadUrl(mUrl);\nwindow.injectedObject.startFunction()\n```\n\n### 生命周期处理\n```java\n@Override\nprotected void onPause() {\n    super.onPause();\n    byWebView.onPause();\n}\n\n@Override\nprotected void onResume() {\n    super.onResume();\n    byWebView.onResume();\n}\n\n@Override\nprotected void onDestroy() {\n    byWebView.onDestroy();\n    super.onDestroy();\n}\n```\n\n### 返回操作\n```java\n@Override\npublic boolean onKeyDown(int keyCode, KeyEvent event) {\n    if (byWebView.handleKeyEvent(keyCode, event)) {\n        return true;\n    } else {\n        return super.onKeyDown(keyCode, event);\n    }\n}\n```\n\n### 上传图片之后的回调\n```java\n@Override\nprotected void onActivityResult(int requestCode, int resultCode, Intent intent) {\n    byWebView.handleFileChooser(requestCode, resultCode, intent);\n}\n```\n\n### 监听 标题、进度条、WebViewClient\n```java\nbyWebView = ByWebView\n        .with(this)\n        .setWebParent(container, new LinearLayout.LayoutParams(-1, -1))\n        .useWebProgress(ContextCompat.getColor(this, R.color.coloRed))\n        .setOnTitleProgressCallback(onTitleProgressCallback)\n        .setOnByWebClientCallback(onByWebClientCallback)\n        .addJavascriptInterface(\"injectedObject\", new MyJavascriptInterface(this))\n        .loadUrl(mUrl);\n```\n```java\nprivate OnTitleProgressCallback onTitleProgressCallback = new OnTitleProgressCallback() {\n    @Override\n    public void onReceivedTitle(String title) {\n        Log.e(\"---title\", title);\n    }\n\n    @Override\n    public void onProgressChanged(int newProgress) {\n        // 返回的进度\n    }\n\n    @Override\n    public boolean onHandleScreenOrientation(boolean isShow) {\n        // 返回true，视频全屏时，横竖屏自己处理\n        return false;\n    }\n};\n\nprivate OnByWebClientCallback onByWebClientCallback = new OnByWebClientCallback() {\n\n    @Override\n    public void onPageStarted(WebView view, String url, Bitmap favicon) {\n        \n    }\n\n    @Override\n    public boolean onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {\n        // 如果自己处理，需要返回true\n        return super.onReceivedSslError(view, handler, error);\n    }\n\n    @Override\n    public void onPageFinished(WebView view, String url) {\n        // 网页加载完成后的回调\n    }\n\n    @Override\n    public boolean isOpenThirdApp(String url) {\n        // 处理三方链接\n        Log.e(\"---url\", url);\n        return ByWebTools.handleThirdApp(ByWebViewActivity.this, url);\n    }\n};\n```\n\n### 自定义错误页面\n\n```java\nByWebView.with(this)\n\t.setErrorLayout(R.layout.by_load_url_error,\"无法打开网页\")\n\t.loadUrl(mUrl);\n```\n\n### 完整设置\n```java\nbyWebView = ByWebView\n        .with(this)\n        .useWebProgress(true) // 是否使用进度条，默认true，如使用可不用配置\n        .setWebParent(container, new LinearLayout.LayoutParams(-1, -1)) // 设置WebView父容器\n        .useWebProgress(\"#ffb6cf\", \"#ff0000\", 3)// 进度条渐变色(开始颜色，结束颜色，高度)\n        .setOnTitleProgressCallback(onTitleProgressCallback)// title 和 progress 监听\n        .setOnByWebClientCallback(onByWebClientCallback)    // WebViewClient监听\n        .setErrorLayout(R.layout.by_load_url_error, \"无法打开网页\") // 设置错误页面及标题\n        .addJavascriptInterface(\"injectedObject\", new MyJavascriptInterface(this)) // 设置Js监听\n        .loadUrl(mUrl);\n```\n\n\n \n## Tip\n - 混淆时应加上（通过JS向网页传值，如不加有时候会传值失败）:\n\n   ```java\n   -keepattributes *Annotation*\n   -keepattributes *JavascriptInterface*\n   -keepclassmembers class * {\n      @android.webkit.JavascriptInterface \u003cmethods\u003e;\n   }\n\t```   \n\n## Thanks\n - [AgentWeb](https://github.com/Justson/AgentWeb)\n\n## Other\n - [WebView的使用及实战](http://www.jianshu.com/p/dbf9b7c04be5)\n - [WebView性能、体验分析与优化](https://tech.meituan.com/WebViewPerf.html)\n - [Android WebView开发问题及优化汇总](http://www.cnblogs.com/spring87/p/4532687.html)\n - [https://developer.android.com/reference/android/webkit/WebSettings.html](https://developer.android.com/reference/android/webkit/WebSettings.html)\n   \n[1]:https://img.shields.io/badge/download-apk-blue.svg?style=flat\n[2]:https://github.com/youlookwhat/download/raw/main/ByWebView.apk\n\n[3]:https://img.shields.io/badge/version-2.7.2-brightgreen.svg?style=flat\n[4]:https://github.com/youlookwhat/download/raw/main/ByWebView.apk\n\n[5]:https://jitpack.io/v/youlookwhat/ByWebView.svg\n[6]:https://jitpack.io/#youlookwhat/ByWebView\n\n[7]:https://img.shields.io/badge/API-14%2B-red.svg?style=flat\n[8]:https://android-arsenal.com/api?level=14","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoulookwhat%2Fbywebview","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyoulookwhat%2Fbywebview","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyoulookwhat%2Fbywebview/lists"}