gpt4 book ai didi

android - 无法从网址下载图片

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

你好请帮忙

Bitmap 在设备上运行时为空,但在 Genymotion(模拟器)上运行时运行良好

我正在尝试从 URL 下载图像当我在 Genymotion(模拟器)中运行它时,它运行良好并显示图像,但是当我在设备上运行它时,位图为空。

下面是代码

public void DisplayImage(String url, ImageView imageView)
{
imageViews.put(imageView, url);
Bitmap bitmap = memoryCache.get(url);
if (bitmap != null)
imageView.setImageBitmap(bitmap);
else {
queuePhoto(url, imageView);
imageView.setImageResource(stub_id);
}
}

这是网址

url=http://www.hugosys.in/www.nett-torg.no/wp-content/uploads/2014/04/Lighthouse3-300x225.jpg

请帮帮我。

最佳答案

您应该使用 jsoup.jar 文件从服务器下载图像。

例如

    String baseUrl = "URL Here";
try
{
Document doc = Jsoup.connect(baseUrl).get();
Elements content = doc.select("a");
Element last = content.last();
lastEle=last.text();
String temp="";
int totalSize;
//
while (!a)
{
temp = content.get(i).text();
a=lastEle.equals(temp);
File f1 = new File(path);

File f = new File(f1, temp);
//Log.d("Image path", f+"");
tmpUrl = baseUrl + temp;
// Log.d("Full URL", tmpUrl);
if(!f.exists())
{
url = new URL(tmpUrl);
HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();

urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();

FileOutputStream fileOutput=new FileOutputStream(f);

InputStream inputStream = urlConnection.getInputStream();
totalSize = urlConnection.getContentLength();

int downloadedSize = 0;
byte[] buffer = new byte[1024];
int bufferLength = 0;
str= "";
while ( (bufferLength = inputStream.read(buffer)) > 0 )
{
fileOutput.write(buffer, 0, bufferLength);
downloadedSize += bufferLength;
}
}
else
{
Log.d("Image Available", "Available");
}
i++;
}
}
catch (IOException e)
{
Log.e(TAG, "Failed to load HTML code", e);
}

关于android - 无法从网址下载图片,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23168097/

25 4 0
文章推荐: javascript - 运行终端应用程序时出现意外的 token 导出
文章推荐: mysql - 如何向引用数据类型 blob 列的表添加外键
文章推荐: javascript - 当我更改选项时将