WebView 从入坑到出坑(一)

持续更新

WebView 从入坑到出坑(二)

  1. 内存泄漏
    前前后后各种找方案,都不行,最终stackOverflow上找到,为webview开启另一个进程: 在AndroidManifest.xml中设置android:process=":remote",完美解决内存泄漏问题
  2. 点击回退建,回到上一个web页面
    这个方法待定,但是确实解决了我的问题。(设置两次goBack)
  @Overridepublic boolean onKeyDown(int keyCode, KeyEvent event) {    
      if (keyCode == KeyEvent.KEYCODE_BACK && webView.canGoBack()) {                
        webView.goBack();        
        webView.goBack();        
        return true;    
      }    
    return super.onKeyDown(keyCode, event);
}
  1. html中超链接
    在我们webview加载的html中有个pdf文件的超链接,ios点击完美打开,没做任何处理,但是Android点击没反应。。。。。。(爬坑中。。。。),望知道的告知下,谢谢!
    解决方案:
  private class MyWebViewDownLoadListener implements DownloadListener {    
      @Override    
      public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {        
          String[] urlSplit = url.split("/");        
          fileName = urlSplit[urlSplit.length - 1];        
          file = new File(Environment.getExternalStorageDirectory(), fileName);        
          if (!file.exists())            
            presenter.fileDownload(url, file);        
          else{            
            Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromFile(file));            
            startActivity(intent);        
          }    
        }
      }

    webView.setDownloadListener(new MyWebViewDownLoadListener());
    Intent intent = new Intent(Intent.ACTION_VIEW,         
    Uri.fromFile(file));startActivity(intent);

PS:就是下载下来,然后用第三方应用打开

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • ¥开启¥ 【iAPP实现进入界面执行逐一显】 〖2017-08-25 15:22:14〗 《//首先开一个线程,因...
    小菜c阅读 6,688评论 0 17
  • 这些都是曾经收集到的一些关于Webview的知识,有些工作中用到了,有些暂时还没有用到,这次统一整理下,希望对自己...
    乆丩乣阅读 11,993评论 14 101
  • 参考 WebView在现在的项目中使用的频率应该还是非常高的。 WebSettingsWebSettings we...
    苏未_阅读 5,164评论 2 8
  • ¥开启¥ 【加群QQ聊天源码】 〖2017-08-25 15:24:36〗 《import "android.ne...
    小菜c阅读 4,312评论 0 5
  • 如果想要拦截事件/离开当前webview 返回true ,否则返回false Android webView拦截u...
    pdog18阅读 318评论 0 0