title: Rendering a local HTML file with a local image in WebView
body: <p>I am trying to render a local html file with a local image in a WebView where the WebView is in a Dialog Box and not an Activity. The image is not being rendered, but the remainder of the info is displayed just fine.</p>
  
  <p>There are countless solutions to this problem suggested in Stack Overflow, many with green check marks. None that I have tried have worked.</p>
  
  <p>What I am doing is placing the html file and the image in res/raw
  The html file has a line referencing the image; I have tried different options all which have been stated somewhere in stack overflow as working, for example:</p>
  
  <pre><code>&lt;img src="file:///android_res/raw/main_screen_crop.png" alt="Main Screen" width="525" height="290"&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>&lt;img src="main_screen_crop.png" alt="Main Screen" width="525" height="290"&gt;
  </code></pre>
  
  <p>The text part of the html renders fine, but for the image I get just the 'alt' text inside an empty box with a thumbnail picture icon.</p>
  
  <p>So the questions I have are:</p>
  
  <ul>
  <li>Is accessing an image when the html of a WebView is rendered inside a Dialog Box different than an Activity making the suggested solutions invalid?</li>
  <li>Some answers said "place the image in the assets directory and use the file:///..." to reference the image AND they indicated that this was required which contradicts other
  solutions. Is the use of the assets directory required?</li>
  <li>Android has a 2018 tutorial <a href="https://www.youtube.com/watch?v=HGZYtDZhOEQ" rel="nofollow noreferrer">https://www.youtube.com/watch?v=HGZYtDZhOEQ</a> stating that many of the StackOverflow answers on how to handle WebView are just plain wrong but admit it is partly their fault due to out of date documentation ...</li>
  </ul>
  
  <p>Here is my render code which works just fine for everything else!</p>
  
  <pre><code>    LayoutInflater inflater = ((Activity)context).getLayoutInflater();
      @SuppressLint("InflateParams") // Okay on dialog
      final View helpContent = inflater.inflate(R.layout.help_screen, null);
  
      // Get the Alert Dialog Builder
      android.support.v7.app.AlertDialog.Builder builder = new android.support.v7.app.AlertDialog.Builder(context);
  
      TextView customTitle = new TextView(context);
      // Customise Title here
      customTitle.setText(title);
      customTitle.setBackgroundColor(context.getResources().getColor(R.color.colorToolbarBackground));
      customTitle.setPadding(10, 10, 10, 10);
      customTitle.setGravity(Gravity.CENTER);
      customTitle.setTextColor(Color.WHITE);
      customTitle.setTextSize(20);
  
      builder.setCustomTitle(customTitle)
      WebView help = helpContent.findViewById(R.id.helpView);
      help.setWebViewClient(new WebViewClient()
      {
          @Override
          public boolean shouldOverrideUrlLoading(WebView view, String url)
          {
              view.loadUrl(url);
              return true;
          }
      });
  
      String helpText = readRawTextFile(htmlpage); // reads the html file
      help.getSettings().setAllowFileAccess(true);  // This did not help ...
      help.loadData(helpText, "text/html; charset=utf-8", "utf-8");
      builder.setView(helpContent); // put view in Dialog box
  </code></pre>
  
  <p>Any help, clarification, etc. as to what is correct will be greatly appreciated!
  Should add that the html file, when clicked on in Windows, renders fine in a browser.</p>