Using httpclient (apache credentials) connection to download various
bitmaps with various devices is failing.... with one is working OK, ¿why?
i'm developing an app for android (java) that it is connecting to a server
to download 50 bitmaps, and i'm using this function each time to download
each bitmap:
public static Bitmap getRemoteBitmap(String url) {
Bitmap bm=null;
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
try {
((AbstractHttpClient)
httpclient).getCredentialsProvider().setCredentials(
new org.apache.http.auth.AuthScope(null,-1),
new
org.apache.http.auth.UsernamePasswordCredentials(MagazineStatus._username,
MagazineStatus._password));
response = httpclient.execute(new HttpGet(url));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK) {
try {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
bm=BitmapFactory.decodeStream(content );
}catch(Exception ex) {Log.e("DBF Error",ex.toString());}
}else {
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
}catch(ClientProtocolException cpe) {Log.e("ClientProtocolException @ at
FPT",cpe.toString());} catch(Exception ex) {Log.e("Exception at
FETCHPROJECTASK",ex.toString());}
return bm;
}
If i try to download the bitmaps with one device, it works fine, but if i
try to download the bitmaps with 3 or 4 devices at the same time, then,
something fails on this function because this line
bm=BitmapFactory.decodeStream(content
); is giving me a a null bitmap, and i dont understand why, because content,
entity, statusLine and response are not null.
These are the values for these variables when the bitmap bm is null:
response:
"response" (id=830078599368)
entity BasicManagedEntity (id=830078617768)
headergroup HeaderGroup (id=830078599408)
locale Locale (id=830078292336)
params ClientParamsStack (id=830079041944)
reasonCatalog EnglishReasonPhraseCatalog (id=830004685872)
statusline BasicStatusLine (id=830078599344)
statusLine:
"statusLine" (id=830078599344)
protoVersion HttpVersion (id=830004713800)
reasonPhrase "OK" (id=830078599288)
statusCode 200
entity:
"entity" (id=830078617768)
attemptReuse false
managedConn null
wrappedEntity BasicHttpEntity (id=830078612272)
content:
"content" (id=830078617792)
skipBuf null
eofWatcher BasicManagedEntity (id=830078617768)
selfClosed false
I'm doing something wrong? is the connection closed properly? can this be
improved? Any help will be apreciated.
Thanks
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en