public void run() { try { // Check for connectivity boolean x = isNetworkAvailable(); if (!x) return; lat = mListener.mLat; lng = mListener.mLng; if (lat == -1) return; Log.d("MAIN", lat + ""); // {"lat": lat, "lng": lng} String s = "{\"lat\": " + lat + "," + "\"lng\":" + lng + "}"; Log.d("MAIN", s); RoadomaticRequest req = new RoadomaticRequest(); final JSONObject resp = req.sendAndReceive(s); if (resp == null) { Log.d("MAIN", "Server is offline"); return; } // {"o": 1, "f": 1, "n": "Shei..", "s": 80} Log.d("MAIN", resp.getInt("s") + ""); final int speed = resp.getInt("s"); // Send the request to the server // Get the street name and the speed // Update the UI mActivity.runOnUiThread( new Runnable() { @Override public void run() { mText.setText(speed + ""); } }); } catch (Exception e) { e.printStackTrace(); } }
public void close() { mRequest.closeSocket(); }