I am developing an application in which I am uploading the latitude and longitude to server after pressing a button on screen the a asynch task is starting and performing the operation and uploading the latitude and longitude to server port. Now the problem is that the gps could not find the latitude and longitude . It throws null on server port. Please help me my code is given below..... Thanks in advance
class Server extends AsyncTask<String, Integer, String> implements LocationListener{
@Override
protected String doInBackground(String... arg0) {
Looper.myLooper();
Looper.prepare();
for(int i=0;i<9898;i++){
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,this);
sendstring=phonenumber+latitude+longitude+"12345467788";
System.out.println(sendstring+"4532748");
stopUsingGPS();
try {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitNetwork().build();
StrictMode.setThreadPolicy(policy);
Socket socket = null;
try {
int REDIRECTED_SERVERPORT=31997;
InetAddress serverAddr = InetAddress.getByName(serverIpAddress);
socket = new Socket(serverAddr, REDIRECTED_SERVERPORT);
} catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())),true);
out.println(sendstring);
/*latitude=0.0;
longitude=0.0;*/
}
catch (UnknownHostException e1) {
e1.printStackTrace();
} catch (IOException e1) {
e1.printStackTrace();
}
catch (Exception e) {
}
}
return call1;
}
@Override
public void onLocationChanged(Location location) {
latitude=location.getLatitude();
longitude=location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onStatusChanged(String provider, int status,
Bundle extras) {
}
public void stopUsingGPS(){
if(locationManager != null){
locationManager.removeUpdates(this);
}
}