Android 可以使用webView 来展示网页内容,也可以使用设备自带的浏览器来进行跳转,

具体怎么使用,比较简单,详细不表。

下面记录下当前开发webapp 遇到的问题:

一、使用webView时,如果网页中包含了echarts等显示的图表。

 webSetting的

setting.setLayoutAlgorithm(LayoutAlgorithm.SINGLE_COLUMN);

最好不要加。

在Android 4.3以上的版本这么加没有问题,但如果Android版本低于4.3(包含4.3),则网页上图表无法正常显示。


二、webView debug

webView中如果调用了JS,debug时,想要在logcat中看到JS的console .log,可以在WebChromeClient 中实现 onConsoleMessage()方法即可

API level 7 和 API level 8以上,参数不一样,下面是官网的例子:

For example, to support API level 7, this is how your code for onConsoleMessage(String, int, String) might look:

WebView myWebView = (WebView) findViewById(R.id.webview);myWebView.setWebChromeClient(new WebChromeClient() {  public void onConsoleMessage(String message, int lineNumber, String sourceID) {    Log.d("MyApplication", message + " -- From line "                         + lineNumber + " of "                         + sourceID);  }});

However, if your lowest supported version is API level 8 or higher, you should instead implementonConsoleMessage(ConsoleMessage). For example:

WebView myWebView = (WebView) findViewById(R.id.webview);myWebView.setWebChromeClient(new WebChromeClient() {  public boolean onConsoleMessage(ConsoleMessage cm) {    Log.d("MyApplication", cm.message() + " -- From line "                         + cm.lineNumber() + " of "                         + cm.sourceId() );    return true;  }});

三、webapp打包混淆

在用proguard 对 含有JS调用的webapp 在打包混淆时,需要对@JavaScriptInterface 做特殊申明,否则JS接口将无法正常调用。

proguard-rules.pro中 添加:

-keepattributes *Annotation*-keepattributes *JavascriptInterface*-keepclassmembers class com.xx.classJavaScirptInterface {   public *;}
 

把com.xx.classJavaScriptInterface 替换成你的类名即可。

附一段官方解释:

# If your project uses WebView with JS, uncomment the following# and specify the fully qualified class name to the JavaScript interface# class:#-keepclassmembers class fqcn.of.javascript.interface.for.webview {#   public *;#}

未完待续...

更多相关文章

  1. android自定义标题栏progressBar
  2. Android6.0 SystemUI之网络信号栏显示刷新
  3. Android与JS交互之基本
  4. 使用MediaPlayer播放声音的异常
  5. Android(安卓)Studio AIDL实现
  6. Android友盟统计和埋点
  7. Android(安卓)Spinner不触发onItemSelected事件
  8. CountDownTimer倒计时器的使用
  9. andriod 4.0以上版本不调用onConfigrationChange方法的解决办法

随机推荐

  1. 5个最佳Android测试框架
  2. android Handler更新UI
  3. Android常用图片加载库介绍及对比
  4. android中查看端口占用
  5. 将tensorflow训练好的模型移植到android
  6. android 手势操作 滑动效果 触摸屏事件处
  7. Android(安卓)判断应用 第一次启动
  8. android控件属性介绍
  9. Android sharedUserId数据权限
  10. 从Android项目学习Kotlin(一)