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

ウィジェットに写真が表示されません。ファイルはもちろん存在します。

4

1 に答える 1

0

これを試してみてください。いくつかの変更の後、それはうまく機能し、私にとってはより良くなっています。

Androidでアプリウィジェットの画像をプログラムで変更する方法

于 2013-12-16T18:24:03.993 に答える