Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Couldn't write bitmap to parcel blob in appwidget in Android 4.2

My app got the following exceptions when trying to display a bitmap:

java.lang.RuntimeException: Could not write bitmap to parcel blob.
    at android.graphics.Bitmap.nativeWriteToParcel(Native Method)
    at android.graphics.Bitmap.writeToParcel(Bitmap.java:1296)
    at android.widget.RemoteViews$BitmapCache.writeBitmapsToParcel(RemoteViews.java:839)
    at android.widget.RemoteViews.writeToParcel(RemoteViews.java:2347)
    at com.android.internal.appwidget.IAppWidgetService$Stub$Proxy.updateAppWidgetIds(IAppWidgetService.java:521)
    at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:364)
    at android.appwidget.AppWidgetManager.updateAppWidget(AppWidgetManager.java:431)

Do you have any idea why this error occurs? It exists only from 4.2. I don't know why and when it happens, I got these exceptions in reports only.

Thanks, Tamas

like image 947
bartat Avatar asked Oct 20 '25 13:10

bartat


1 Answers

I think I have found the answer. If I check jni/android/graphics/Bitmap.cpp then I can see:

size_t size = bitmap->getSize();

android::Parcel::WritableBlob blob;
android::status_t status = p->writeBlob(size, &blob);
if (status) {
    doThrowRE(env, "Could not write bitmap to parcel blob.");
    return false;
}

It seems that the problem is about the bitmap size not the bitmap itself.

writeBlob function can return NO_MEMORY status if memory couldn't be allocated.

So I guess if a user sets a too large bitmap then it can fail this way.

like image 159
bartat Avatar answered Oct 22 '25 03:10

bartat