title: Android WebView load from internal storage | Android 11 | Android R
body: <p>Actually my requirement is I want to load dynamic files into WebPage like image. video, audio etc.., it's either from asset or apps own files directory, that's not a problem.</p>
  <p>I tried using following two ways.</p>
  <p><strong>Way 1</strong></p>
  <p>Here is my html file is in assets folder, and I have <code>123.jpg</code> in both assets folder and also internal folder,</p>
  <p>Home.html,</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
     &lt;head&gt;
        &lt;title&gt;Page Title&lt;/title&gt;
     &lt;/head&gt;
     &lt;body&gt;
        &lt;h1&gt;Image testing&lt;/h1&gt;
        &lt;p&gt;Relative Path&lt;/p&gt;
        &lt;img src=&quot;123.jpg&quot; alt=&quot;Italian Trulli&quot; width=&quot;100%&quot;&gt;
        &lt;p&gt;From Files Directory&lt;/p&gt;
        &lt;img src=&quot;file:////data/user/0/com.guna.testapplication/files/123.jpg&quot; alt=&quot;Italian Trulli&quot; width=&quot;100%&quot;&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And I am loading it into webview like</p>
  <pre><code>webView.loadUrl(&quot;file:///android_asset/Home.html&quot;)
  </code></pre>
  <p><strong>And here is my output for 29,</strong></p>
  <p><a href="https://i.stack.imgur.com/Vki3d.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Vki3d.png" alt="enter image description here" /></a></p>
  <p>Look, both from Asset and files directory loaded as expected.</p>
  <p><strong>And here is for 30,</strong></p>
  <p><a href="https://i.stack.imgur.com/Ytpfj.png" rel="noreferrer"><img src="https://i.stack.imgur.com/Ytpfj.png" alt="enter image description here" /></a></p>
  <p>Here only from asset directory loaded. And files directory not loaded.</p>
  <p><strong>Way 2</strong></p>
  <p>Here I'm loading both html and image from internal storage.</p>
  <p>Home.html</p>
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
     &lt;head&gt;
        &lt;title&gt;Page Title&lt;/title&gt;
     &lt;/head&gt;
     &lt;body&gt;
        &lt;h1&gt;Image testing&lt;/h1&gt;
        &lt;img src=&quot;123.jpg&quot; alt=&quot;Italian Trulli&quot; width=&quot;100%&quot;&gt;
     &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  <p>And I'm loading webview like this,</p>
  <pre><code>webView.loadUrl(&quot;file:////data/user/0/com.guna.testapplication/files/Home.html&quot;)
  </code></pre>
  <p>If my <code>compileSdkVersion 29</code> and also <code>targetSdkVersion 29</code> this works well,</p>
  <p><strong>Output for 29</strong></p>
  <p><a href="https://i.stack.imgur.com/CKuBH.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CKuBH.png" alt="enter image description here" /></a></p>
  <p>If I change SdkVersion like <code>compileSdkVersion 30</code> and also <code>targetSdkVersion 30</code> this gives me access denied error,</p>
  <p><strong>Output on 30</strong></p>
  <p><a href="https://i.stack.imgur.com/HRioG.png" rel="noreferrer"><img src="https://i.stack.imgur.com/HRioG.png" alt="enter image description here" /></a></p>
  <p><strong>Manifest</strong></p>
  <pre><code>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;
  &lt;application
      android:allowBackup=&quot;true&quot;
      android:icon=&quot;@mipmap/ic_launcher&quot;
      android:label=&quot;@string/app_name&quot;
      android:roundIcon=&quot;@mipmap/ic_launcher_round&quot;
      android:supportsRtl=&quot;true&quot;
      android:theme=&quot;@style/AppTheme&quot;
      android:usesCleartextTraffic=&quot;true&quot;&gt;
      &lt;activity
          android:name=&quot;.MainActivity&quot;
          android:exported=&quot;true&quot;&gt;
          &lt;intent-filter&gt;
              &lt;action android:name=&quot;android.intent.action.MAIN&quot; /&gt;
  
              &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot; /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
  &lt;/application&gt;
  </code></pre>