app widget setImageViewUri does not update the image

后端 未结 3 1070
情深已故
情深已故 2020-12-17 17:52

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 ur

3条回答
  •  囚心锁ツ
    2020-12-17 18:50

    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())); 
    

提交回复
热议问题