Android带有图片更改的小部件

3

我正在尝试制作一个小部件,它可以在特定时间从SD卡中更改图像。我的onUpdate函数如下:

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

但是我在小部件上看不到任何照片。当然,文件是存在的。

1个回答

0

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接