3

I'm trying to make a widget which changes image in specific timeer from sdcard. My onUpdate function looks like:

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.main);
ComponentName thisWidget = new ComponentName(context, PhotoWidgetProvider.class);
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) 
    mExternalStorageWriteable = true;

if(mExternalStorageWriteable) {
    BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2;
    //of course it's a sample filename
String fileName = Environment.getExternalStorageDirectory().getPath() + "/DCIM/100MEDIA/IMAG0159.jpg";
Bitmap bitmap = BitmapFactory.decodeFile(fileName, options);
remoteViews.setImageViewBitmap(R.id.widget_imageview, bitmap);
    appWidgetManager.updateAppWidget(thisWidget, remoteViews);
}

but I can not see any photo on my widget. File of course exists.

1 Answers1

0

Try this one. After some modification it's working fine and for me better.

How to change the image in app widget programmatically in android

Community
  • 1
  • 1