shouldOverrideUrl使用loadDataWithBaseURL无法处理本地映像

时间:2017-06-20 21:47:18

标签: android android-webview

我正在使用loadDataWithBaseURL方法加载本地html。

我用源代码调用了setHTML,并且进展顺利。链接是有效的,正如我在之前关于stackoverflow的问题中看到的那样,所以一切都已设置。

当用户点击链接时,它会正常工作并打开ArticleActivity,但是当他点击图片(来自html)时,即使图片有链接,也不会调用该方法

这里会出现什么问题?

 public void setHTML(String source) {
    Document doc = Jsoup.parse(source);
    String html = WebHelper.docToBetterHTML(doc, this);
    mHTMLWebView.loadDataWithBaseURL(mLink, html, "text/html", "UTF-8", "");
    mHTMLWebView.setVisibility(View.VISIBLE);
}


mHTMLWebView.setWebViewClient(new WebViewClient(){

        @Override
        public void onPageFinished(WebView view, String url) {
            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    Animation fade = AnimationUtils.loadAnimation(mLoadingLayout.getContext(), android.R.anim.fade_out);
                    mLoadingLayout.startAnimation(fade);
                    mLoadingLayout.setVisibility(View.GONE);
                }
            },500);
        }


        public boolean shouldOverrideUrlLoading(WebView view, String url){
            //super.shouldOverrideUrlLoading(view,url);
            if(url != null
                    && (url.endsWith(".png") || url
                    .endsWith(".jpg") || url
                    .endsWith(".jpeg"))){
                // Launch imageviewer
                ArrayList<String> list = new ArrayList<>();
                list.add(url);


                try{
                    new ImageViewer.Builder(view.getContext(), list)
                            .setStartPosition(0)
                            .show();
                } catch (Exception e){
                    e.printStackTrace();
                }
            }  else if (url != null
                    && url.contains("dkhlak.com")){
                Intent intent = new Intent(view.getContext(),ArticleActivity.class);
                intent.putExtra("link",url);
                view.getContext().startActivity(intent);

            } else {
                Intent ViewIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
                try{
                    view.getContext().startActivity(ViewIntent);
                } catch (Exception e){
                    e.printStackTrace();
                }

            }
            return true;
        }
        });

示例:

<p>\u0625\u0646 \u0639\u0627\u0644\u0645\u0646\u0627 \u0645\u0643\u0627\u0646\u064c \u063a\u0631\u064a\u0628\u064c \u062c\u062f\u0627\u064b\u060c \u0641\u0641\u064a \u0628\u0639\u0636 \u0627\u0644\u0623\u062d\u064a\u0627\u0646 \u064a\u0648\u062c\u062f \u0623\u0634\u064a\u0627\u0621\u064c \u0643\u062b\u064a\u0631\u0629 \u0646\u0638\u0646\u0647\u0627 \u0639\u0627\u062f\u064a\u0629\u060c \u0644\u0643\u0646\u0647\u0627 \u0642\u062f \u062a\u0643\u0648\u0646 \u0641\u064a \u0646\u0638\u0631 \u063a\u064a\u0631\u0646\u0627 \u0645\u0646 \u0627\u0644\u0646\u0627\u0633 \u063a\u064a\u0631 \u0639\u0627\u062f\u064a\u0629\u060c \u0628\u0644 \u0623\u0646\u0647\u0645 \u0642\u062f \u064a\u0631\u0648\u0646\u0647\u0627 \u0642\u0628\u064a\u062d\u0629. \u0644\u0643\u0646 \u0641\u064a \u0627\u0644\u0646\u0647\u0627\u064a\u0629 \u064a\u0648\u062c\u062f \u0623\u0634\u064a\u0627\u0621 \u0646\u062c\u0645\u0639 \u0643\u0644\u0646\u0627 \u0639\u0644\u0649 \u0642\u0628\u062d\u0647\u0627 \u0648\u0628\u063a\u0636\u0647\u0627\u060c \u0648\u0630\u0644\u0643 \u0644\u0623\u0646\u0647\u0627 \u063a\u064a\u0631 \u0625\u0646\u0633\u0627\u0646\u064a\u0629 \u0648\u0638\u0627\u0644\u0645\u0629 \u0644\u062f\u0631\u062c\u0629 \u063a\u064a\u0631 \u0642\u0627\u0628\u0644\u0629 \u0644\u0644\u062a\u0635\u0648\u0631.<\/p>\n<p>\u0648\u0645\u0647\u0645\u0627 \u0643\u0627\u0646 \u0642\u0628\u062d \u062a\u0644\u0643 \u0627\u0644\u0623\u0634\u064a\u0627\u0621 \u0643\u0628\u064a\u0631\u0627\u064b\u061b \u064a\u0628\u0642\u0649 \u0644\u062f\u064a\u0646\u0627 \u0641\u0636\u0648\u0644 \u0643\u0628\u064a\u0631 \u0644\u0645\u0639\u0631\u0641\u0629 \u0645\u0627\u0647\u064a\u062a\u0647\u0627\u060c \u0641\u0641\u064a \u0627\u0644\u0645\u0642\u0627\u0644 \u0627\u0644\u062a\u0627\u0644\u064a \u0633\u0646\u0639\u0631\u0636 \u0644\u0643\u0645 \u0633\u062a \u0639\u0634\u0631\u0629 \u062d\u0642\u064a\u0642\u0629 \u0635\u0627\u0631\u062e\u0629 \u062c\u0627\u0648\u0632\u062a \u0641\u064a \u0642\u0628\u062d\u0647\u0627 \u0623\u0628\u0639\u062f \u0627\u0644\u062d\u062f\u0648\u062f:<\/p>\n<p><strong>1. \u0641\u064a \u0645\u0637\u0644\u0639 \u0627\u0644\u0642\u0631\u0646 \u0627\u0644\u0639\u0634\u0631\u064a\u0646\u060c \u0639\u064f\u0631\u0636 \u0627\u0644\u0631\u062c\u0644 \u0627\u0644\u0643\u0648\u0646\u063a\u0648\u0644\u064a Ota Benga \u0641\u064a \u0623\u062d\u062f \u0623\u0642\u0641\u0627\u0635 \u0627\u0644\u0642\u0631\u062f\u0629 \u0641\u064a \u062d\u062f\u064a\u0642\u0629 Bronx \u0643\u0646\u0645\u0648\u0630\u062c \u062d\u064a \u0644\u0645\u0631\u0627\u062d\u0644 \u0627\u0644\u062a\u0637\u0648\u0631 \u0627\u0644\u0628\u0634\u0631\u064a\u0629 \u0627\u0644\u0645\u0628\u0643\u0631\u0629. \u0645\u0635\u064a\u0631 Benga \u0625\u0646\u062a\u0647\u0649 \u0628\u0625\u0642\u062f\u0627\u0645\u0647 \u0639\u0644\u0649 \u0627\u0644\u0625\u0646\u062a\u062d\u0627\u0631 \u0646\u062a\u064a\u062c\u0629 \u0644\u0633\u0648\u0621 \u0627\u0644\u0645\u0639\u0627\u0645\u0644\u0629 \u0627\u0644\u062a\u064a \u062a\u0639\u0631\u0636 \u0625\u0644\u064a\u0647\u0627\u060c \u0648\u0627\u0644\u0625\u0643\u062a\u0626\u0627\u0628 \u0627\u0644\u0630\u064a \u0623\u0635\u0627\u0628\u0647 \u0644\u0627\u062d\u0642\u0627\u064b.<\/strong><em>\u00a0\u2014<a href=\"https:\/\/en.wikipedia.org\/wiki\/Ota_Benga\" rel=\"nofollow\">\u0627\u0644\u0645\u0635\u062f\u0631<\/a><\/em><\/p>\n<div id=\"attachment_15079\" style=\"width: 1034px\" class=\"wp-caption aligncenter\"><img class=\"size-full wp-image-15079\" src=\"https:\/\/dkhlak.com\/wp-content\/uploads\/2017\/06\/15071-1.jpg\" alt=\"\u0627\u0644\u0631\u062c\u0644 \u0627\u0644\u0643\u0648\u0646\u063a\u0648\u0644\u064a Ota Benga\" width=\"1024\" height=\"580\" srcset=\"https:\/\/dkhlak.com\/wp-content\/uploads\/2017\/06\/15071-1.jpg 1024w, https:\/\/dkhlak.com\/wp-content\/uploads\/2017\/06\/15071-1-400x227.jpg 400w, https:\/\/dkhlak.com\/wp-content\/uploads\/2017\/06\/15071-1-768x435.jpg 768w, https:\/\/dkhlak.com\/wp-content\/uploads\/2017\/06\/15071-1-810x459.jpg 810w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/>

0 个答案:

没有答案