Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing binary blob through a content provider
    primarykey
    data
    text
    <p>I have a content provider that is custom to my set of Android applications, and one of the things it needs to expose is a small (20-30 KiB) byte array. The URI for these blobs looks like:</p> <pre><code>content://my.authority/blob/# </code></pre> <p>where <code>#</code> is the row number; the resulting cursor has the standard <code>_id</code> column and a data column. I'm using a <code>MatrixCursor</code> in the provider's <code>query()</code> method:</p> <pre><code>byte[] byteData = getMyByteData(); MatrixCursor mc = new MatrixCursor(COLUMNS); mc.addRow(new Object[] { id, byteData }); </code></pre> <p>Later, in the application consuming the data, I do:</p> <pre><code>Cursor c = managedQuery(uri, null, null, null, null); c.moveToFirst(); byte[] data = c.getBlob(c.getColumnIndexOrThrow("data")); </code></pre> <p>However, data does not contain the contents of my original byte array; rather, it contains something like <code>[B@435cc518</code>, which looks more like the address of the array than the contents. I tried wrapping the byte array in an implementation of <code>java.sql.Blob</code>, figuring that it might be looking for that since the content provider subsystem was written to be easy to use with SQLite, but it didn't help.</p> <p>Has anyone gotten this to work? If the data was in the file system, there are methods in <code>ContentProvider</code> that I could use to provide a marshalled <code>InputStream</code> to the client, but the data I'm trying to send back lives as a resource in the content provider's APK.</p>
    singulars
    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.
 

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