user2872856 user2872856 - 9 months ago 80
Android Question

Load Images from Assets in Widget remoteView

I am using the following code to load my image into Android widget


remoteViews.setImageViewResource(, R.drawable.image);

I have to save the image in
folder. Is it possible to save the image in assets instead and load it to


Using BitmapFactory, you can load an image in assets/ as a Bitmap from an InputStream provided by AssetManager, and then use the RemoteViews#setImageViewBitmap() method to set it on your widget.

For example:

RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);

try {
    InputStream is = context.getAssets().open("image.jpg");
    Bitmap bmp = BitmapFactory.decodeStream(is);

    remoteViews.setImageViewBitmap(, bmp);
catch (IOException e) {