1

Actually I have a php page which is on the server.

See this: http://webfreezesolution.com/ochat/map2.php

When I open this link in BROWSER on any device, it automatically refreshes in 5 seconds and update the current location of the user to a text file on the server.

But when I call this URL in a Service in my android project via HttpURLConnection, my text file on the server is updating blank (I mean the last modified timing is updating of the file but the location is not written in the file. It is just updating blank).

I just want to update the current location of the android device to the text file on the server in background service.

Below is the code I am using to refresh my page in every 10 seconds:

public void readWebPage(){

      URL url;
      HttpURLConnection con = null;
      try {
          url = new URL("http://webfreezesolution.com/ochat/map2.php");
          con = (HttpURLConnection) url.openConnection();
          con.setRequestMethod("GET");
          con.setDoInput(true);
          con.addRequestProperty("Referer", "http://webfreezesolution.com/");
          con.connect();
          readStream(con.getInputStream());
          } catch (Exception e) {
          e.printStackTrace();
        }
      finally {
          if(con != null)
            con.disconnect();
       }

}

class MyThread extends Thread{
    static final long DELAY = 10000;
    @Override
    public void run(){          
        while(isRunning){
            Log.d(TAG,"Running");
            try {                   
                readWebPage();
                Thread.sleep(DELAY);
            } catch (InterruptedException e) {
                isRunning = false;
                e.printStackTrace();
            }
        }
    }

}

}

Why I am unable to send the current location to server in android service?

Please help.

Thanks in advance.

0 Answers0