Image in android widget


  1. lesio

    lesio New Member

    I'm trying to make a widget which changes displayed image from sdcard in specific timeer. My onUpdate function looks like:
    [HIGH]
    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);
    }
    }
    [/HIGH]But I can not see any photo on my widget. File of course exists.

    Advertisement

Share This Page