gpt4 book ai didi

android - 在 appwidget 中延迟加载图像

转载 作者:行者123 更新时间:2023-11-29 16:20:41 25 4
gpt4 key购买 nike

有没有办法将互联网上的图像延迟加载到远程 View 中。

remoteView.setImageViewBitmap(R.id.image, UrlUtils.loadBitmap(bitmapUrl));

我使用此功能,但它会在短时间内阻止我的小部件。

public static Bitmap loadBitmap(String url) {
Bitmap bitmap = null;
InputStream in = null;
BufferedOutputStream out = null;

try {

in = new BufferedInputStream(getPageInputStream(url));

final ByteArrayOutputStream dataStream = new ByteArrayOutputStream();
out = new BufferedOutputStream(dataStream);
Utils.copy(in, out);
out.flush();

final byte[] data = dataStream.toByteArray();
BitmapFactory.Options options = new BitmapFactory.Options();
// options.inSampleSize = 1;

bitmap = BitmapFactory.decodeByteArray(data, 0, data.length,
options);

in.close();
out.close();

} catch (IOException e) {
e.printStackTrace();
}

return bitmap;
}

谢谢

最佳答案

绝对

  1. 以通常的方式绘制您的小部件,在图像旁边绘制所有文本部分等
  2. 创建一个加载图像的服务。 Here's good tutorial包括如何从 appwidget 创建和调用服务
  3. 更新您的小部件后调用该服务。传递小部件 ID 和图像 URL
  4. 从缓存中加载图像或在您的服务中远程加载图像,然后再次更新您的小部件。瞧,你现在有了

关于android - 在 appwidget 中延迟加载图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7349198/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com