private class Notific extends AsyncTask<String, Void, Void> {
VariablesGlobals global = (VariablesGlobals) getApplicationContext();
ProgressDialog Dialog = new ProgressDialog(Notificaciones.this);
BufferedReader reader = null;
JSONArray resultDatos;
JSONObject jsonResult;
JSONObject d;
String data = "";
String Content;
String result;
protected void onPreExecute() {
Dialog.setMessage("Cargando...");
Dialog.setCancelable(false);
Dialog.show();
}
protected Void doInBackground(String... urls) {
try
{
String serverURL = "aqui va tu url con los parametros a enviar por get";
URL url = new URL(serverURL);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
Content = reader.readLine().toString(); // content te regresara en string lo que conteste tu ws
}
catch(Exception e)
{
Log.e("Exception", e.toString());
}
finally
{
try { reader.close(); }
catch(Exception ex) {}
}
return null;
}
protected void onPostExecute(Void unused) {
try {
jsonResult = new JSONObject(Content); // convertir en objeto
result = jsonResult.getString("resultado");
if(result.equals("false"))
{
texto = new TextView(Notificaciones.this);
texto.setText("No tienes Notificaciones pendientes");
texto.setTextSize(12);
texto.setGravity(1);
texto.setTextColor(0xFFFFFFFF);
texto.setPadding(7, 9, 7, 9);
texto.setBackground(getResources().getDrawable(R.drawable.notificacion));
layoutNotificaciones.addView(texto);
}
else
{
result = jsonResult.getString("datos");
if(result.equals("false"))
{
texto = new TextView(Notificaciones.this);
texto.setText("No tienes Notificaciones pendientes");
texto.setTextSize(12);
texto.setGravity(1);
texto.setTextColor(0xFFFFFFFF);
texto.setPadding(7, 9, 7, 9);
texto.setBackground(getResources().getDrawable(R.drawable.notificacion));
layoutNotificaciones.addView(texto);
}
else
{
resultDatos = jsonResult.getJSONArray("datos");
for (int i = 0; i < resultDatos.length(); i++) {
d = resultDatos.getJSONObject(i);
titulo.add(d.getString("titulo").toString());
mensaje.add(d.getString("mensajecorto").toString());
mensajelargo.add(d.getString("mensaje").toString());
estatus.add(d.getString("estatus").toString());
rowid.add(d.getString("rowid").toString());
color = "colorSinLeer";
if(d.getString("estatus").equals("1"))
color = "colorLeido";
c.add(color);
}
setupList();
}
}
} catch (JSONException e) {
e.printStackTrace();
}
Dialog.dismiss();
}
}