내 목표는 안드로이드 응용 프로그램과 함께 Google 애플 리케이션 엔진 서버에서 이미지를 다운로드하는 것입니다. 나는 asynctask를 사용한다. 서버는 Google 앱 엔진에 있으며 이미지 (JPEG 파일)는 BLOBSTORE에 있습니다. 먼저 서버가 내 Google 크롬 브라우저에서 작동하는지 확인했습니다. 브라우저에서 같은 URI를 가진 그림을 볼 수있었습니다. 그래서 제 서버가 잘 작동하고 있습니다. 내 연결에 세션이 있으며 https 연결입니다. 내 애플 리케이션은 drawable (또는 비트 맵?)으로 이미지를 다운로드하고 배열을 만들어이 배열을 갤러리 용 imageadapter에 넣어야한다. 문제는 Drawable을 할 때 myImage = Drawable.createFromStream (is, "Image"); myImage가 null입니다. (If (myImage == null)로 확인). 내 브라우저에서 이미지를 표시하는 이유는 무엇입니까?내가 다운로드 할 수있는 이미지는 null입니다.
추 신 : 많은 검색을했는데 웹에서 이미지를 다운로드 할 수있는 대안이 많이 있습니다. 그러나 이것이 왜 작동하지 않는지 나는 이해할 수 없다. 안드로이드 2.2에서 코드를 실행했습니다. 어떤 생각에 대한
URI uri = new URI(URIString);
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);
Scheme sch = new Scheme("https", socketFactory, 443);
httpclient.getConnectionManager().getSchemeRegistry().register(sch);
HttpGet httpget = new HttpGet(uri);
System.out.println(httpget.getURI());
HttpResponse response = httpclient.execute(httpget, myLibrary.localContext);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
Drawable myImage= Drawable.createFromStream(is, "Image");
entity.consumeContent();
if (myImage!=null){
System.out.println("PhotoID " + PhotoID + " is NOT null!");
return myImage;
} else {
System.out.println("PhotoID " + PhotoID + " is null!");
return null;
}
감사 : 여기
코드입니다!
요청과 함께 보내는 데 중요한 사용자 에이전트 문자열을 확인 했습니까? –
사용중인 URI가 System.out에 인쇄됩니다. 해당 URI를 복사하여 브라우저에 붙여 넣었습니다. 그것은 효과가 있었다. 따라서 URI는 요청에 충분해야합니다. 세션 또는 https에 관한 것일 수 있습니까? 나는 모른다 : S – Genom