Skip to content Skip to sidebar Skip to footer

App Widget Setimageviewuri Does Not Update The Image

i have an app widget, which contains only one imageview. i redraw that image and store it as png in apps's private memory and then i set the RemoteViews' image with the uri (widget

Solution 1:

If the Uri remains unchanged, it seems Android won't update the image. I've found a bit of a hack to get around this though. Just call widget.setImageViewUri(R.id.widget_icon, Uri.parse("")); before widget.setImageViewUri(R.id.widget_icon, uri);.

It calls setImageViewUri() twice, but seems to be working OK. I'd love to hear a better way to fix it though, as I'm experiencing this issue myself.

Solution 2:

Well it looks like setImageViewUri caches images and does not refresh them if the have the same name.

Not the most elegant solution but it works, every second time it will use a different file name.

String filename = new String("bitmap-1.png");
// rotate files, due to not being refreshed if same name if ( context.deleteFile(filename) ) {
   filename = new String("bitmap-0.png");
}
FileOutputStream out = context.openFileOutput(filename, Context.MODE_WORLD_READABLE);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, out);
file = context.getFileStreamPath(filename);
out.close();
updateViews.setImageViewUri(R.id.image1,Uri.parse(file.toString())); 

Solution 3:

I hope this helps anyone else. I was trying to use that method in a remove list view but it never worked. But using bitmaps worked for me. I was able to update pictures in any of the records and they were updating and there was no caching. This is the static method I used.

publicstaticBitmapgetBitmap(String imageLocation ) {

    BitmapFactory.Options options = newBitmapFactory.Options();
    options.inPreferredConfig = Bitmap.Config.ARGB_8888;

    returnBitmapFactory.decodeFile(imageLocation, options);
}

then

bitmap = BitmapUtils.getBitmap( address.getPhotoLocation() );
row.setImageViewBitmap( R.id.row_image, bitmap );

Post a Comment for "App Widget Setimageviewuri Does Not Update The Image"