WebView with base64 doesn't loading the images

你。 提交于 2019-12-24 20:12:10

问题


I have a webView and I'm getting the webContent as String from a connection getting the response and change it into inserting into database and getting it in the Main2Activity but like I said after changing it into base64 encodeToString the pictures doesn't show it even if I didn't change it into base64 it doesn't show anything. for offline use

 public static String getHtml(String url) throws IOException {


    // Build and set timeout values for the request.
    URLConnection connection = (new URL(url)).openConnection();
    connection.setConnectTimeout(5000);
    connection.setReadTimeout(5000);
    connection.connect();

    // Read and store the result line by line then return the entire string.
    InputStream in = connection.getInputStream();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder html = new StringBuilder();
    for (String line; (line = reader.readLine()) != null; ) {
        html.append(line);
    }
    in.close();

    return html.toString();
}

this is how i get the string and my string looks like in the Log

<!DOCTYPE html><html id="js-context" class="js-off is-not-modern id--signed-out" lang="en" data-page-path="/money/2019/dec/10/starbucks-gift-card-refused-franchise-stores"><head><!--     __        __                      _     _      _     \ \      / /__    __ _ _ __ ___  | |__ (_)_ __(_)_ __   __ _      \ \ /\ / / _ \  / _` | '__/ _ \ | '_ \| | '__| | '_ \ / _` |       \ V  V /  __/ | (_| | | |  __/ | | | | | |  | | | | | (_| |        \_/\_/ \___|  \__,_|_|  \___| |_| |_|_|_|  |_|_| |_|\__, |                                                            |___/    Ever thought about joining us?    https://workforus.theguardian.com/careers/digital-development/     ---><title>The Starbucks gift card I bought is useless | Money | The Guardian</title><meta charset="utf-8"><meta name="description" content="It won’t accept it at the Leicester University franchise and the nearest alternative is an hour away"/><meta http-equiv="X-UA-Compatible" content="IE=Edge"/><meta name="format-detection" content="telephone=no"/><meta name="HandheldFriendly" content="True"/><meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"><link rel="dns-prefetch" href="https://assets.guim.co.uk/"/><link rel="dns-prefetch" href="https://i.guim.co.uk"/><link rel="dns-prefetch" href="https://api.nextgen.guardianapps.co.uk"/><link rel="dns-prefetch" href="https://hits-secure.theguardian.com"/><link rel="dns-prefetch" href="//j.ophan.co.uk"/><link rel="dns-prefetch" href="//ophan.theguardian.com"/><link rel="dns-prefetch" href="//phar.gu-web.net"/><link rel="dns-prefetch" href="//www.google-analytics.com"/><link rel="preconnect" href="https://assets.guim.co.uk/"/><link rel="preconnect" href="https://i.guim.co.uk"/><link rel="preconnect" href="//interactive.guim.co.uk"/><link rel="preconnect" href="//www.google-analytics.com"/><link rel="dns-prefetch" href="//sb.scorecardresearch.com"/><link rel="apple-touch-icon" sizes="152x152" href="https://assets.guim.co.uk/images/favicons/fee5e2d638d1c35f6d501fa397e53329/152x152.png"/><link rel="apple-touch-icon" sizes="144x144" href="https://assets.guim.co.uk/images/favicons/1fe70b29879674433702d5266abcb0d4/144x144.png"/><link rel="apple-touch-icon" sizes="120x120" href="https://assets.guim.co.uk/images/favicons/c58143bd2a5b5426b6256cd90ba6eb47/120x120.png"/><link rel="apple-touch-icon" sizes="114x114" href="https://assets.guim.co.uk/images/favicons/68cbd5cf267598abd6a026f229ef6b45/114x114.png"/><link rel="apple-touch-icon" sizes="72x72" href="https://assets.guim.co.uk/images/favicons/873381bf11d58e20f551905d51575117/72x72.png"/><link rel="apple-touch-icon-precomposed" href="https://assets.guim.co.uk/images/favicons/6a2aa0ea5b4b6183e92d0eac49e2f58b/57x57.png"/><link rel="manifest" href="/2015-06-24-manifest.json" crossorigin="use-credentials"><link rel="amphtml" href="https://amp.theguardian.com/money/2019/dec/10/starbucks-gift-card-refused-franchise-stores"><link rel="shortcut icon" type="image/png" href="https://assets.guim.co.uk/images/favicons/46bd2faa1ab438684a6d4528a655a8bd/32x32.ico"/><link rel="canonical" href="https://www.theguardian.com/money/2019/dec/10/starbucks-gift-card-refused-franchise-stores"/><meta name="apple-mobile-web-app-title" content="Guardian"/><meta name="application-name" content="The Guardian"/><meta name="msapplication-TileColor" content="#052962"/><meta name="theme-color" content="#052962"><meta name="msapplication-TileImage" content="https://assets.guim.co.uk/images/favicons/023dafadbf5ef53e0865e4baaaa32b3b/windows_tile_144_b.png"/><link rel="publisher" href="https://plus.google.com/113000071431138202574"/><meta name="author" content="Rebecca Smithers"/><meta name="thumbnail" content="https://i.guim.co.uk/img/media/843b4d2dc4f73319eba6210d4d68509119b702c2/0_0_4096_2458/master/4096.jpg?width=620&amp;quality=85&amp;auto=format&amp;fit=max&amp;s=adbfbb41f5b50749f72609024e473493"/><meta name="keywords" content="Consumer rights,Money,Starbucks,Retail industry"/><meta name="news_keywords" content="Consumer rights,Money,Starbucks,Reta

this is the webView codes in the main activity that i get the string from the database by id number

     web_View = findViewById(R.id.webView);

     web_View.setWebViewClient(new WebViewClient());

     if (CheckInternet.isNetwork(getApplicationContext())) {
        if(url2!=null) {
            Log.e("url2", url2);
            web_View.loadUrl(url2);
        }
       } else {

        int data = getUrl.getIntExtra("data",0);


       String a = FavNewsDatabase.getInstance(getApplicationContext()).noteDao().loadSingle(data);
            Log.e("data2",a);
        String encodedHtml = Base64.encodeToString(a.getBytes(), Base64.NO_PADDING);

    web_View.loadData(encodedHtml, "text/html", "base64");

    }

how I can open it with the images and THANKS

来源:https://stackoverflow.com/questions/59262395/webview-with-base64-doesnt-loading-the-images

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!