Created
August 22, 2013 13:22
-
-
Save shriduttkothari/6307073 to your computer and use it in GitHub Desktop.
On a valid RomInfo Object received, Start the Downloader AsyncTask to download the update zip file from server, the doInBackground() method will have pseudo code as follows:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private int doInBackground(Void... notused) { | |
final File dest = new File("/cache/update.zip"); | |
InputStream is = null; | |
OutputStream os = null; | |
try { | |
URL getUrl = new URL(romInfo.url); | |
destFile.getAbsolutePath()); | |
URLConnection conn = getUrl.openConnection(); | |
conn.connect(); | |
is = new BufferedInputStream(conn.getInputStream()); | |
os = new FileOutputStream(destFile); | |
byte[] buf = new byte[4096]; | |
int nRead = -1; | |
int totalRead = 0; | |
while ((nRead = is.read(buf)) != -1) { | |
os.write(buf, 0, nRead); | |
totalRead += nRead; | |
} | |
// Verify Md5 checksum here | |
} catch (Exception e) { | |
e.printStackTrace(); | |
destFile.delete(); | |
} finally { | |
if (is != null) { | |
try { is.close(); } | |
catch (Exception e) { } | |
} | |
if (os != null) { | |
try { os.flush(); os.close(); } | |
catch (Exception e) { } | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment