Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The trick is to create a ParcelFileDescriptor.createPipe() to copy the database file through streams to the WebView.</p> <p>LocalImageContentProvider.java</p> <pre><code>public class LocalImageContentProvider extends ContentProvider { private static final String AUTHORITY = "com.example.local.provider"; public static final Uri CONTENT_URI = Uri.parse("content://"+ AUTHORITY +"/image"); @Override public ParcelFileDescriptor openFile(Uri uri, String mode) { String filename = uri.getLastPathSegment(); // http://developer.android.com/reference/android/os/ParcelFileDescriptor.html#createPipe%28%29 // [0] is the reader, [1] is the writer ParcelFileDescriptor[] pipe = null; try { pipe = ParcelFileDescriptor.createPipe(); // copy DB file through pipe to WebView new Thread(new PipeRunnable( getInputStreamFromDbFile(filename), new AutoCloseOutputStream(pipe[1])) ) .start(); } catch (IOException e) { e.printStackTrace(); } return (pipe[0]); } } </code></pre> <p>Manifest.xml</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;manifest xmlns:android="http://schemas.android.com/apk/res/android" &gt; &lt;uses-sdk android:minSdkVersion="9" android:targetSdkVersion="19"/&gt; &lt;application&gt; &lt;!-- 'activity --&gt; &lt;provider android:exported="false" android:name=".provider.LocalImageContentProvider" android:authorities="com.example.local.provider" /&gt; &lt;/application&gt; &lt;/manifest&gt; </code></pre> <p>To load images in the WebView use the ContentProvider URI + "/image.jpg":<br> <code>&lt;img src="content://com.example.local.provider/image/29.jpg"&gt;&lt;/img&gt;</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload