hi im new to AsyncTask and i need to send data to API server. im doing the connection and im stuck here. i read about the AsyncTask and this is the code that i've seen. first thing is if i determine if the device is connected, it will send data on the URL given, else. it will send thru SMS
public class SendData extends AsyncTask <String, Void, Boolean> {
DateFormat dateFormat = new SimpleDateFormat("MMM dd, yyyy HH:mm:ss");
Date date = new Date();
String datefinal = dateFormat.format(date).toString();
String url = "http://192.168.1.212/mobile_alerts_api.php?location=&msg=&datetime=&id=";
@Override
protected Boolean doInBackground(String... urls) {
try{
HttpGet httppost = new HttpGet(url);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
// StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
return true;
}
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
}
}