how to handle if I have poor internet connection or the if I lost my connection , I can't handle it in java class, In Activity I could check the internet Connection but here NO, So I'm tying to handle the internet connection while tracking
@Override
public void onLocationChanged(Location location) {
sharedPreferences = mContext.getSharedPreferences(PREFS_NAME, 0);
editor = sharedPreferences.edit();
emailSharedPref = sharedPreferences.getString("email", "");
Log.e("emailLocation", emailSharedPref);
Log.i("long", "" + location.getLongitude() + " TIME: " + t.time());
getAdress(location.getLatitude(),location.getLongitude());
JSONObject jsonObject = new JSONObject();
URLPath urlPath = new URLPath();
String serverURL = urlPath.trackEmployee;
WebServiceRequest request = new WebServiceRequest();
request.setUrl(serverURL);
try {
jsonObject.put("latitude", location.getLatitude());
jsonObject.put("longitude", location.getLongitude());
jsonObject.put("street", street);
jsonObject.put("district", district);
jsonObject.put("city", city);
jsonObject.put("time", t.time());
jsonObject.put("date", t.date());
jsonObject.put("email", sharedPreferences.getString("email", ""));
Log.e("jsonLocation", jsonObject.toString());
} catch (JSONException e)
{
e.printStackTrace();
}
request.setRequestBody(jsonObject);
WebServiceAsyncTask webService = new WebServiceAsyncTask();
WebServiceRequest[] requestArr = {request};
webService.execute(requestArr);
}
public void getAdress(double longt, double lat) {
try {
addresses = geocoder.getFromLocation(longt, lat, 1);
} catch (IOException e) {
e.printStackTrace();
}
if (addresses != null) {
street = addresses.get(0).getAddressLine(0);
district = addresses.get(0).getAddressLine(1);
city = addresses.get(0).getAddressLine(2);
connection="on";
Log.d("connection",connection+".."+addresses.toString());
}else{
connection="off";
Log.d("connection",connection);
}
}