Ok so I have my app 90% built everything works but my download button. I have been stuck on this for days now so if anyone could help a guy out with something that will work for this. my files are .pkg and I feed the filename from a xml file and here is my buttons code but I dont know what I am doing wrong here. It just does nothing upon clicking it. The appUrl is my file name from the xml file
Button b_get_book = (Button)v.findViewById(R.id.Button01);
b_get_book.setOnClickListener(
new View.OnClickListener()
{
public void onClick(View v) {
try {
File root = Environment.getExternalStorageDirectory();
URL u = new URL("http://www.mysite.com/" + appUrl);
HttpURLConnection c = (HttpURLConnection) u.openConnection();
c.setRequestMethod("GET");
c.setDoOutput(true);
c.connect();
FileOutputStream f = new FileOutputStream(new File(root, appUrl));
InputStream in = c.getInputStream();
byte[] buffer = new byte[1024];
int len1 = 0;
while ((len1 = in.read(buffer)) > 0) {
f.write(buffer, 0, len1);
}
f.close();
} catch (Exception e) {
Log.d("Downloader", e.getMessage());
}
}
});
Any help would be great I have been pulling my hair out over this. I make a pretty complex app and its the easy thing that gets me...... go figure. if anyone can help me out with some working code from a button that would be awesome. even better if it has a progress bar for the downloads. that is my next task after getting the actual download working. Thanks