Results 1 to 1 of 1
- 09-06-2011, 05:57 PM #1
Member
- Join Date
- Sep 2011
- Posts
- 1
- Rep Power
- 0
Problems downloading a remote binary file with Eclipse and Android
I'm currently working on a small Java/Android app which should download a remote binary file and save it locally. This app should run on an Android device, more precisely a Samsung Galaxy S GTI9000. I'm currently using Eclipse SDK Version 3.7.0. Below is the code causing the problem:
As one of the above code comments says (//THIS INSTRUCTION LEADS TO A CRASH!), the problem comes when the instruction conexion.connect() is executed: at this point program very often crashes, although this happens quite often but not always (and I cannot understand why) and the phone's logcat shows the message: W/InputManagerService (2251): Got RemoteException sending setActive(false) notification to pid 3817 uid 10091. I tried to use conexion.setDoInput(true) but problem persists.Java Code:public void downloadRemoteSceneFile() { //TODO: pass scene file name as a parameter String strSceneFileName = "http://www.mysite.com/myfolder/myremotebinaryfile.dat" ; int count; try { URL url = new URL(strSceneFileName); if(url == null) return ; //Remember to import java.net.HttpURLConnection ; at file begin //if you want to use HttpURLConnection instead of URLConnection HttpURLConnection conexion = (HttpURLConnection)url.openConnection() ; if(conexion == null) return ; //Use these two instructions if using HttpURLConnection instead of URLConnection conexion.setRequestMethod("GET") ; //conexion.setDoOutput(true) ; //conexion.setDoInput(true) ; //conexion.setDoOutput(false) ; conexion.connect(); //THIS INSTRUCTION LEADS TO A CRASH !!!!!! // this will be useful so that you can show a tipical 0-100% progress bar int lenghtOfFile = conexion.getContentLength() ; // downlod the file InputStream input = new BufferedInputStream(url.openStream()); OutputStream output = new FileOutputStream("/sdcard/somewhere/nameofthefile.ext"); byte data[] = new byte[1024]; while ((count = input.read(data, 0, 1024)) != -1) { total += count; //publishing the progress.... publishProgress((int)(total*100/lenghtOfFile)); updateRemoteFileDownloadProgressBar((float)total / (float)lenghtOfFile) ; output.write(data, 0, count); } output.flush(); output.close(); input.close(); } catch (Exception e) { Log.v("TEST", "inside catch(Exception e)") ; System.out.println("!!!!!!!!! System.out.println - inside catch(Exception e) !!!!!!!!!") ; } finally { Log.v("TEST", "inside finally") ; } }
Also please note that I have already added inside AndroidManifest.xml the line with the permission to access the Internet (<uses-permission android:name="android.permission.INTERNET" />).
Anyone can help?
Thanks in advance!
Similar Threads
-
RFC: Dev Machine for Eclipse/Android/Internet usage
By blackbird in forum EclipseReplies: 0Last Post: 08-01-2011, 04:34 PM -
Problems with Binding a socket on a remote machine
By vishwas.shashidhar in forum NetworkingReplies: 0Last Post: 06-08-2011, 06:01 PM -
Android on Eclipse
By cselic in forum EclipseReplies: 2Last Post: 05-20-2010, 01:40 PM -
Android on Eclipse 3.2
By aibtus in forum EclipseReplies: 0Last Post: 04-08-2008, 11:11 AM -
Problems with downloading Files from Applet
By Albert in forum Java AppletsReplies: 1Last Post: 07-05-2007, 05:09 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks