0
URL에서 SD 카드로 이미지를 다운로드했습니다. 그것은 SD 카드에 정상적인 썸네일 이미지로 표시되지만 메시지를 보려면 그것을 클릭하면 Could not load image
이미지가 imageview에 표시 할 수 없습니다 표시됩니다. Async Task를 사용하여 이미지를 다운로드했습니다. 이제는 이미지가 표시 가능한지 여부를 먼저 확인하고 싶습니다. 삭제하지 않으면 다시 다운로드하십시오. 이미지를 다운로드Android : 이미지가 다운로드되었지만 이미지보기에 표시되지 않았습니다.
코드는 :
protected Void doInBackground(String... params) {
try{
String fileName = params[0].substring(params[0].lastIndexOf('/') + 1);
URL url = new URL(params[0]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.setDoOutput(true);
urlConnection.connect();
File file = new File(SwipeActivity.filename,fileName);
FileOutputStream fileOutput = new FileOutputStream(file);
InputStream inputStream = urlConnection.getInputStream();
byte[] buffer = new byte[1024];
int bufferLength = 0;
while ((bufferLength = inputStream.read(buffer)) > 0)
{
fileOutput.write(buffer, 0, bufferLength);
}
fileOutput.close();
}
catch (Exception e) {
// TODO: handle exception
}
return null;
}
어떤 도움을 사전에 감사합니다.
이 github 링크는 이미지 다운로드뿐만 아니라 UI 파트의 이미지 표시에도 도움이 될 것이라고 생각합니다. https://github.com/nostra13/Android-Universal-Image-Loader –
이미지를 다운로드하는 데 사용하는 해당 코드를 게시하고 이미지 뷰로 설정하는 방법을 게시 할 수 있습니까? –
@swapnil 매우 도움이됩니다. 친절하게도 동시에 다운로드 방법을 알려줍니다. –