Note that there are some explanatory texts on larger screens.

plurals
  1. POStoring a Bitmap into a ContentProvider from a BroadcastReciever
    text
    copied!<p>I'm working on an app that, upon instillation of certain apps will send a message to them to register with a content provider. It all works fine, the strings are stored, but I can't get the byte[] blob (a bitmap .png file) to convert properly from within onRecieve() in the broadcastreciever.</p> <pre><code>@Override public void onReceive(Context context, Intent intent) { Log.v("xxxxxxxxxxxxx", "onReceive, from within RegisterApp"); this.context = context; ContentValues values = new ContentValues(); values.put("app_name", getAppName()); values.put("app_description", getAppDescription()); ByteArrayOutputStream stream = new ByteArrayOutputStream(); Bitmap b = getAppIcon(); b.compress(Bitmap.CompressFormat.PNG, 0, stream); byte[] blob = stream.toByteArray(); values.put("icon", blob); context.getContentResolver().insert( Uri.parse("content://blahblahblahblah"), values); } </code></pre> <p>I hijack the context so that I can get a hold on the image from the getAppIcon() call (You extend this class which is an abstract class extending BroadcastReceiver)</p> <p>i.e.</p> <pre><code>@Override protected Bitmap getAppIcon() { Log.v(TAG, "putting icon"); return BitmapFactory.decodeResource(this.context.getResources(), R.drawable.icon); } </code></pre> <p>But my understanding of the context is limited and I think this is what is causing it to be stored incorrectly. </p> <p>I've also tried getting the bitmap from the resources when onRecieve() is called and that doesn't work either. </p> <p>I'm at a loss, any assistance would be appreciated.</p>
 

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