Hi Guys,
I'm new here, and I'm just trying to learn the ropes of android. Okay,
so here's my question:
I've got a method that I've tested successfully and found that it
works in Java. However, when I convert it over to android, and try to
run it on my emulator, it doesnt work. Basically, the method takes
the input parameters beginning, end, and URL, and downloads a file or
file segment from the URL parameter with beginning at byte position
beginning and ending at byte position end. In the emulator, it wont
download but in Java, it works just fine.
I've enabled internet permissions, and I've tested the other parts of
my activity so I don't think thats the problem. Heres my code, maybe
you guys can help.
public void download(int beginning, int end, String address) throws
IOException{
URL url;
int read = 0;
android.util.Log.d(TAG,"DL Started");
byte buffer[] = new byte[1024];
url = new URL(address);
URLConnection fileAddress = url.openConnection();
fileAddress.setAllowUserInteraction(true);
fileAddress.setRequestProperty("Range","bytes=" + beginning +
"-" +
end);
InputStream is = fileAddress.getInputStream();
DataOutputStream out = new DataOutputStream(new
BufferedOutputStream
(new FileOutputStream("/sdcard/Test")));
android.util.Log.d(TAG,"DL in the midst");
while (read !=300 ){
is.read(buffer);
out.write(buffer);
read++;
}
out.close();
android.util.Log.d(TAG,"File is:
"+fileAddress.getContentLength() +
" bytes");
//while((bytereader = is.read()) != beginning); // while byte
is not
beginning of the segment
//return 0;
}
--
You received this message because you are subscribed to the Google
Groups "Android Beginners" 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-beginners?hl=en