I am trying to download files in my application. The functionality
has worked for many phones until now. The Evo will not download the
files. My following code works on the Nexus 1, Droid, etc, but not
the Evo. There is never anything in the entity.getContent()
For downloading images:
HttpClient httpclient = new DefaultHttpClient();
URI uri = new URI(url);
HttpGet getter = new HttpGet(uri);
HttpResponse r = httpclient.execute(getter);
b = BitmapFactory.decodeStream(r.getEntity().getContent());
For downloading any file:
URI uri = new URI(url);
HttpGet httpget = new HttpGet(uri);
Log.i("blah", url);
response = httpclient.execute(httpget);
Header [] headers = response.getAllHeaders();
for(Header header : headers){
Log.i("blah", header.getName() + " " +
header.getValue());
}
Log.i("blah", "Header length: " + headers.length);
Log.i("blah", "reason: " +
response.getStatusLine().getReasonPhrase());
Log.i("blah", "status code: " +
response.getStatusLine().getStatusCode());
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instream = entity.getContent();
File root = Environment.getExternalStorageDirectory();
File f=new File(root, "/TBSA/" + filename);
OutputStream out=new FileOutputStream(f);
byte buf[]=new byte[1024];
int len;
while((len=instream.read(buf))>0){
Log.i("blah", "read bytes");
out.write(buf,0,len);
}
out.close();
instream.close();
}
In the second section of code, the response is OK and the code is
200. When I download an MS Word file, there are 8 headers, including
one that says Content-Type application/msword.
--
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