1. Check out our companion app, Forums for Android! Download from Google Play

Image in android widget

Discussion in 'Android Apps & Games' started by lesio, Nov 30, 2012.

  1. lesio

    lesio New Member
    Thread Starter

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


Share This Page