X5、WebViewJavascriptBridge、百度地图网页版 整合注意事项
2016-06-16 19:46
459 查看
一 什么是webViewjavascripBridge?
WebViewJavascriptBridge是移动UIView和Html交互通信的桥梁,用作者的话来说就是实现java(ios为oc)和js的互相调用的桥梁。替代了WebView的自带的JavascriptInterface的接口,使得我们的开发更加灵活和安全。WebViewJavascriptBridge
for Android
https://github.com/jesse01/WebViewJavascriptBridge
WebViewJavascriptBridge
for iOS/OSX
https://github.com/marcuswestin/WebViewJavascriptBridge
注意:使用4.1.5版才能跟安卓的保持一致:
pod 'WebViewJavascriptBridge','4.1.5'
二 什么是X5
TBS2.1基于Android 5.0 WebView Blink内核(M37版本)适配定制优化,适配Android全部主流平台,可以支持移动应用App在所有Android手机上使用Blink的技术能力。TBS2.1支持Service Worker,可以帮助Web应用后台运行,提供离线访问等原生App应用体验。此外,TBS2.1在H5/CSS3支持,安全,可靠,性能方面有进一步提升。TBS2.1已经发布,将逐步在各客户端中静默升级,用户终端无需更新微信、手机QQ、QQ空间即可使用最新的TBS2.1Blink内核。
x5接入文档
三 接入注意事项
1、X5与WebViewJavascriptBridge
private class MyWebChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { return super.onJsConfirm(view, url, message, result); } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { return super.onJsPrompt(view, url, message, defaultValue, result); } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { callback.invoke(origin, true, false); super.onGeolocationPermissionsShowPrompt(origin, callback); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { if (mUploadMessage != null) return; Log.e("openFileChooser", "openFileChooser"); mUploadMessage = uploadMsg; selectImage(); // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // i.addCategory(Intent.CATEGORY_OPENABLE); // i.setType("*/*"); // startActivityForResult( Intent.createChooser( i, "File Chooser" ), FILECHOOSER_RESULTCODE ); } // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg) { openFileChooser(uploadMsg, ""); } // For Android > 4.1.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } }
GeolocationPermissions.Callback 替换为 GeolocationPermissionsCallback
修改为:
private class MyWebChromeClient extends WebChromeClient { @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { return super.onJsAlert(view, url, message, result); } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { return super.onJsConfirm(view, url, message, result); } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { return super.onJsPrompt(view, url, message, defaultValue, result); } @Override public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissionsCallback callback) { callback.invoke(origin, true, false); super.onGeolocationPermissionsShowPrompt(origin, callback); } public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { if (mUploadMessage != null) return; Log.e("openFileChooser", "openFileChooser"); mUploadMessage = uploadMsg; selectImage(); // Intent i = new Intent(Intent.ACTION_GET_CONTENT); // i.addCategory(Intent.CATEGORY_OPENABLE); // i.setType("*/*"); // startActivityForResult( Intent.createChooser( i, "File Chooser" ), FILECHOOSER_RESULTCODE ); } // For Android < 3.0 public void openFileChooser(ValueCallback<Uri> uploadMsg) { openFileChooser(uploadMsg, ""); } // For Android > 4.1.1 public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileChooser(uploadMsg, acceptType); } }
2,X5与百度地图网页版
地图加载慢或者加载不出来的情况 ,发现是因为
1、x5没能打开GPS定位权限,建议提示将GPS、WiFi、4G网络定位都打开。
2、第一次加载百度地图去下载的网页元素太大
相关文章推荐
- Android ListView实现通讯录的实例
- 调用Android中相机或图库选择图片并剪切
- 微信企业号开发01 - 获取corpid 和 corpsecret
- 初始化TableViewCell时获取到的宽度错误
- 调用Android的相机与图库并进行剪切
- Object-C 中各数据类型转换 NSData转NSString,Byte,UIImage
- <Android学习笔记五>Android系统自带样式(android:theme)详解
- android 读取资源文件的数据
- 支付宝支付
- Android Studio 2.2 Preview 2 生成的界面问题
- Android内存泄漏解决方案(OOM)
- 苹果开发者相关联系方式,包括app加急审核
- Volley
- Android libs/armeabi下面的动态库没有安装到app-lib的问题
- iOS使用Charts框架绘制—饼状图
- 图片拉伸并保护关键部分不变形
- UIApplication介绍
- android开发—Fragment中onCreateView()和onActivityCreated()的区别
- 微信测试号设置
- iOS 实现第三方登录(图文)