ok, this was a tough one.
First be informed that this is something Google (Android people) are trying to prevent i.e. letting browser (WebView) have access to the local file system. In earlier releases of SDK you could access local files using ‘file://’ but it is stopped now. Then there was an option where you can provide a WebViewClient and implement shouldOverrideUrlLoading to make it work. This was also removed.
The way to make it work now is by implementing your own ContentProvider, there is lot of discussion and documentation on implementing ContentProvider but all that is completely redundant (not needed). The solution is very simple, create your own ContentProvider and only override

<br />
public android.os.ParcelFileDescriptor openFile(android.net.Uri uri, java.lang.String mode) throws java.io.FileNotFoundException<br />

Rest of the code in ContentProvder is not needed for this problem.

Step 1:
Declare your Content Provider in AndroidManifest.xml

<provider android:name="MyDataContentProvider"  android:authorities="com.techjini" />

Step 2:
Create your ContentProvider and implement openFile
All you have to do is get real path from uri, open it and return the descriptor

<br />
URI uri = URI.create(&#8220;file:///data/data/com.techjini/files/myImage.jpeg&#8221;);<br />
File file = new File(uri);<br />
ParcelFileDescriptor parcel = ParcelFileDescriptor.open(file, ParcelFileDescriptor.MODE_READ_ONLY);<br />
return parcel;<br />

Step 3:
(You need this step only if file is not already present on the device/sdcard)
Save your content to the file. Following is an example to store a Bitmap

<br />
FileOutputStream fos = openFileOutput(&#8220;myImage.jpeg&#8221;, Activity.MODE_WORLD_WRITEABLE);<br />
imageView.getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fos);</p>
<p>fos.flush();<br />
fos.close();<br />

You can find out where your image is stored using

<br />
System.out.println(getFilesDir().getAbsolutePath());<br />

Step 4:
Access the file in WebView

<br />
myWebView.loadUrl(&#8220;content://com.techjini/myImage.jpeg&#8221;);<br />
//com.techjini is what you mentioned in &#8216;android:authorities&#8217; in your AndroidManifest.xml<br />

Looks simple :)

Buy Zetia online