Last active
December 21, 2015 12:38
-
-
Save shriduttkothari/6306808 to your computer and use it in GitHub Desktop.
Create an AsyncTask, which can be called whenever polling is required to be performed to check the update on server, the doInBackground() method will have pseudo code as follows:
This file contains hidden or 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 RomInfo doInBackground(Void... notused) { | |
//Check Network availability | |
ArrayList<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>(); | |
params.add(new BasicNameValuePair("device",android.os.Build.DEVICE.toLowerCase())); | |
params.add(new BasicNameValuePair("rom", Utils.getRomID())); | |
HttpClient client = new DefaultHttpClient(); | |
HttpGet get = new HttpGet(SERVER_PULL_URL + "?" + URLEncodedUtils.format(params, "UTF-8")); | |
HttpResponse r = client.execute(get); | |
int status = r.getStatusLine().getStatusCode(); | |
HttpEntity e = r.getEntity(); | |
if (status == 200) { | |
String data = EntityUtils.toString(e); | |
JSONObject json = new JSONObject(data); | |
if (json.has("error")) { | |
error = json.getString("error"); | |
return null; | |
} | |
return new RomInfo( | |
json.getString("rom"), | |
json.getString("version"), | |
json.getString("changelog"), | |
json.getString("url"), | |
json.getString("md5"), | |
Utils.parseDate(json.getString("date"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment