【问题标题】:Android widget with image changing具有图像更改功能的 Android 小部件
【发布时间】:2012-11-23 11:34:17
【问题描述】:

我正在尝试制作一个小部件,它可以从 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);
}

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

【问题讨论】:

    标签: android image widget


    【解决方案1】:

    试试这个。经过一些修改,它工作正常,对我来说更好。

    How to change the image in app widget programmatically in android

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-03-25
      • 2011-10-30
      • 2014-06-07
      • 2021-03-10
      相关资源
      最近更新 更多