我正在尝试制作一个小部件,它可以从 sdcard 更改特定计时器中的图像。我的 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);
}
但我在我的小部件上看不到任何照片。文件当然存在。