java - Android downloading series of files Not working -
I need a function that downloads files by passing the name and url, so that I download a series of files in the Android app Can do
Then went ahead and created something like this:
public zero doDownload (string filename, string url) {file root = android.os.Environment.getExternalStorageDirectory ( ); File directory = new file (root.atgeolute path (+ + "/ content /"); If (dir.exists () == incorrect) {dir.mkdirs (); } {URL url = Try the new URL (url); URL Connection Connection = url.openConnection (); Connection.connect (); // This will be useful so that you can show a normal 0-100% progress bar int file length = connection.getContentLength (); Logs. I ("ANDRO_ASYNC", "file length:" + file length); // file inputstream input = download new BufferedInputStream (url.openstream ()); OutputStream Output = New File OpticalStream (DIR + Filename); Byte data [] = new byte [1024]; Long total = 0; integer number; While ((count = input.read (data))! = -1) {total + = count; Output.write (data, 0, count); } Output.flush (); Output.close (); Input.close (); } Catch (Exception E) {}} XML: Added permission
Now when I call this function:
< Code> doDownload (string img.png, string http://server.com); This does not give any file here What's wrong?
Another option is using the download manager to download the file. You can try to use DownloadManager to view the Android Developer site check this link:
Comments
Post a Comment