Last active
December 27, 2015 12:39
-
-
Save lithid/7327067 to your computer and use it in GitHub Desktop.
json
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
public String getNetFile(String device, String url, boolean isJ) { | |
DefaultHttpClient defaultClient = new DefaultHttpClient(); | |
String urlStr = url; | |
HttpGet httpGetRequest = new HttpGet(urlStr); | |
HttpResponse httpResponse = null; | |
try { | |
httpResponse = defaultClient.execute(httpGetRequest); | |
} catch (IllegalStateException e) { | |
return null; | |
} catch (IllegalArgumentException e) { | |
return null; | |
} catch (ClientProtocolException e) { | |
return null; | |
} catch (IOException e) { | |
return null; | |
} | |
BufferedReader reader = null; | |
try { | |
reader = new BufferedReader(new InputStreamReader(httpResponse | |
.getEntity().getContent(), "UTF-8")); | |
} catch (NullPointerException e) { | |
return null; | |
} catch (UnsupportedEncodingException e) { | |
return null; | |
} catch (IllegalStateException e) { | |
return null; | |
} catch (IOException e) { | |
return null; | |
} | |
String json = null; | |
StringBuilder total = new StringBuilder(); | |
try { | |
while ((json = reader.readLine()) != null) { | |
if (json.equals("<!doctype html>")) { | |
return null; | |
} | |
total.append(json + "\n"); | |
} | |
} catch (NullPointerException e) { | |
return null; | |
} catch (IOException e) { | |
return null; | |
} | |
return total.toString(); | |
} |
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
class loadAllUpdates extends AsyncTask<String, String, String> { | |
@Override | |
protected void onPreExecute() { | |
setProgressBarIndeterminateVisibility(true); | |
} | |
@Override | |
protected String doInBackground(String... arg0) { | |
String json = mUtils.getNetFile(url); | |
try { | |
JSONObject jsonObject = new JSONObject(json); | |
mArray = jsonObject.getJSONArray("updates"); | |
int success = jsonObject.getInt("success"); | |
mRom = jsonObject.get("_name").toString(); | |
switch (success) { | |
case 1: | |
for (int i = 0; i < mArray.length();) { | |
JSONObject c = mArray.getJSONObject(i); | |
mId = c.getlong("_ID"); | |
mFile = c.getString("_FILE"); | |
mMd5sum = c.getString("_MD5SUM"); | |
mVersion = c.getString("_VERSION"); | |
mChangelog = c.getString("_CHANGELOG"); | |
mDate = c.getint("_DATE"); | |
return mId; | |
} | |
return json; | |
case 0: | |
return null; | |
} | |
} catch (NullPointerException e) { | |
return null; | |
} catch (JSONException e) { | |
return null; | |
} | |
return json; | |
} | |
@Override | |
protected void onPostExecute(final String string) { | |
setProgressBarIndeterminateVisibility(false); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment