0

I have been trying to figure out almost 2 weeks. I have read previous posts and tried the proposed solutions but they didn't work for me.

Iam using Android Studio, I need Webview to access a local Jpg stored in Android Assets file.

Here is my code:

webView = (WebView) findViewById(R.id.webview);
startWebView("file:///android_asset/railchinese.jpg");
webView.getSettings().setBuiltInZoomControls(true);
webView.getSettings().setDisplayZoomControls(true);
webView.getSettings().setSupportZoom(true);
webView.getSettings().setUseWideViewPort(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setLoadWithOverviewMode(true);

private void startWebView(String url) {
    webView.setWebViewClient(new WebViewClient() {
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    });
    webView.loadUrl(url);

Here is the Assets location screen:

enter image description here

Kindlly let me know where is the mistake?..

APC
  • 144,005
  • 19
  • 170
  • 281

1 Answers1

0

Try this

String htmlData="<img src= railchinese.png>";

webView.loadDataWithBaseURL("file:///android_asset/", htmlData, "text/html", "utf-8", null);
Jemo Mgebrishvili
  • 5,187
  • 7
  • 38
  • 63