Thanks CommsWare. Because of the space limitation in the comment field, I'm using this way to respond.
The users are supposed to take a photo of an item they are about to pickup and send it to the server. After this is done, the server sends back a polling cycle period for the phone to send its location periodically. I've set up the textViews
to show the acquired lat/long (see below), but this part wasn't working until two nights ago. It did finally work after I was a little more patient and let the phone take its time to acquire a position. I think the problem then was that I wasn't allowing the phone to acuire a position fix, so it wasn't working. The problem remains now that the periodic updates may not work, based on what you have said, and based on the fact that I stood outside under completely clear sky for about 2 mins before I got a position fix.
Here's a snapshot of some of the code (this part is in the main activity's onCreate override to get the first location fix):
`LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new LocationListener() {
public void onStatusChanged(String provider, int status,
Bundle extras) {
// called when the provider status changes. Possible
// status: OUT_OF_SERVICE, TEMPORARILY_UNAVAILABLE or
// AVAILABLE.
}
public void onProviderEnabled(String provider) {
// called when the provider is enabled by the user
}
public void onProviderDisabled(String provider) {
// called when the provider is disabled by the user, if
// it's already disabled, it's called immediately after
// requestLocationUpdates
}
public void onLocationChanged(Location location) {
double latitute = location.getLatitude();
double longitude = location.getLongitude();
tv5.setText(""+latitute);
tv6.setText(""+longitude);
}
});
`
Below is part of the SOAP request and response handling mechanism.
`//Get the polling period in seconds.
String[] getPollNumber;
getPollNumber = resultParams[2].split(";");
//Set up the intent to be passed to the tracking service.
Intent updateLocation = new Intent (this,TrackUser.class);
PendingIntent pendingIntent = PendingIntent.getService(PickUp.this, 0, updateLocation, 0);
//Set up the alarm manager to be used to periodically send updates.
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
//If instruction = 1, start tracking the user.
if(instruction == 1)
{
//Start tracking service on phone.
pollPeriod = Integer.parseInt(getPollNumber[0]);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (pollPeriod*1000), pollPeriod*1000, pendingIntent);
}
else
{
if(instruction == 0)
{
//Stop tracking service.
stopService(new Intent(this,TrackUser.class));
alarmManager.cancel(pendingIntent);
}
}
'
In the tracking service class, I use a method called from its onStart() override that simply packages the current coordinates into a SOAP object and updates the server. I'm worried that the GPS may not have sufficient time to lock on during these updates if the phone goes to sleep like you said. I'm wondering if when the service is started I should have a timer of some sort (maybe the minTime setting of requestLocationUpdates?) hold the phone awake for about 3 minutes so a fix could come in? Please let me know if these code snippets help, and if the idea for updating the position is possible, thanks.