Passing binary blob through an Android content provider
Posted
by velocityb0y
on Stack Overflow
See other posts from Stack Overflow
or by velocityb0y
Published on 2010-06-14T01:14:02Z
Indexed on
2010/06/14
1:22 UTC
Read the original article
Hit count: 683
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-30k) byte array. The uri for these blobs looks like content://my.authority/blob/# where # is the row number; the resulting cursor has the standard _id column and a data column. I'm using a MatrixCursor in the provider's query method:
byte[] byteData = getMyByteData();
MatrixCursor mc = new MatrixCursor(COLUMNS);
mc.addRow(new Object[] { id, byteData });
Later, in the application consuming the data, I do
Cursor c = managedQuery(uri, null, null, null, null);
c.moveToFirst();
byte[] data = c.getBlob(c.getColumnIndexOrThrow("data"));
However, data does not contain the contents of my original byte array; rather, it contains something like "[B@435cc518", which looks more like the address of the array than the contents. I tried wrapping the byte array in an implementation of java.sql.Blob, 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.
Has anyone gotten this to work? If the data was in the file system, there are methods in ContentProvider that I could use to provide a marshalled InputStream to the client, but the data I'm trying to send back lives as a resource in the content provider's APK.
© Stack Overflow or respective owner