String TextHolder = "", TextHolder2 = "";
public class GetNotePadFileFromServer extends AsyncTask<Void, Void, Void> {
@Override
protected void onPreExecute() {
super.onPreExecute();
progressDialog.show();
}
@Override
protected Void doInBackground(Void... params) {
String userId = SharedPrefHelper.getPrefsHelper().getPref(SharedPrefHelper.PREF_USER_ID);
try {
URL url = new URL(baseUrl+"fileName.xml");
BufferedReader bufferReader = new BufferedReader(new InputStreamReader(url.openStream()));
while ((TextHolder2 = bufferReader.readLine()) != null) {
TextHolder += TextHolder2;
}
bufferReader.close();
} catch (MalformedURLException malformedURLException) {
malformedURLException.printStackTrace();
TextHolder = malformedURLException.toString();
} catch (IOException iOException) {
iOException.printStackTrace();
TextHolder = iOException.toString();
}
return null;
}
@Override
protected void onPostExecute(Void finalTextHolder) {
Document doc = convertStringToXMLDocument( TextHolder );
doc.getDocumentElement().normalize();
NodeList nList = doc.getElementsByTagName(ApiConstant.ApiKeys.SMS_MESSAGE);
for (int temp = 0; temp < nList.getLength(); temp++) {
Node nNode = nList.item(temp);
if (nNode.getNodeType() == Node.ELEMENT_NODE) {
Element eElement = (Element) nNode;
Sms sms = new Sms(
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_IDS).item(0).getTextContent(),
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_ADDRESS).item(0).getTextContent(),
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_BODY).item(0).getTextContent(),
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_READ).item(0).getTextContent(),
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_DATE).item(0).getTextContent(),
eElement.getElementsByTagName(ApiConstant.ApiKeys.SMS_TYPE).item(0).getTextContent(),
false
);
LogClass.e("mysms",""+sms.getAddress());
smsArrayList.add(sms);
}
}
setUi();
progressDialog.dismiss();
super.onPostExecute(finalTextHolder);
}
}
new GetNotePadFileFromServer().execute();