我尝试使用远程视图从url设置图像。这是我使用的代码。 我调试了我的代码和我的字符串
(this: String ab = (MainActivity.itemList.get(0)
.get(MainActivity.KEY_image)).toString();) is for example some image's url (for example,http://google.com/mypic.png)
这是我的代码:
RemoteViews views;
int appWidgetId;
public File file;
public Bitmap bitmap;
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
if (CLOCK_WIDGET_UPDATE.equals(intent.getAction())) {
Toast.makeText(context, "onReceiver()", Toast.LENGTH_LONG).show();
}
}
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidgetIds.length;
for (int i = 0; i < N; i++) {
appWidgetId = appWidgetIds[i];
Intent intent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
intent, 0);
views = new RemoteViews(context.getPackageName(),
R.layout.widget_demo);
String aa = (MainActivity.itemList.get(0)
.get(MainActivity.KEY_title)).toString();
views.setOnClickPendingIntent(R.id.widgetPic, pendingIntent);
views.setOnClickPendingIntent(R.id.widgetDesc, pendingIntent);
views.setTextViewText(R.id.widgetDesc, aa);
String ab = (MainActivity.itemList.get(0)
.get(MainActivity.KEY_image)).toString();
views.setImageViewUri(R.id.widgetPic, Uri.parse(ab));
// views.setImageViewBitmap(
// R.id.widgetPic,
// ((BitmapDrawable) context.getResources().getDrawable(
// R.drawable.aaaaaaaaaaaaaaa)).getBitmap());
appWidgetManager.updateAppWidget(appWidgetId, views);
}
}
public void updateAppWidget(Context context,
AppWidgetManager appWidgetManager, int appWidgetId) {
RemoteViews updateViews = new RemoteViews(context.getPackageName(),
R.layout.widget_demo);
try {
} catch (Exception e) {
}
appWidgetManager.updateAppWidget(appWidgetId, updateViews);
}
}
如何使用setImageViewUri
显示此图片?如果有人知道解决方案,请帮助我。
感谢。