Hi,
My class listed below is not working. No idea whatsoever. The
onLocationChanged method is never getting called !
I checked the logs for any errors/exceptions. I have the required
permissions set (fine and course locations).
I doubt the Context I'm setting from the caller. I'm using
getApplicationContext() to pass to the setContext method in this
class.
Can anyone please help ?
public class GPSSensor implements CASensor {
private String LTAG = this.getClass().getName();
Context myContext;
private String GPSData;
public LocationManager lMgr;
public LocationListener myLocListener = new LocationListener() {
public void onStatusChanged(String provider, int status, Bundle
extras) {
Log.v(LTAG, "=========== Here 1 ============");
}
public void onProviderEnabled(String provider) {
Log.v(LTAG, "=========== Here 2 ============");
}
public void onProviderDisabled(String provider) {
Log.v(LTAG, "=========== Here 3 ============");
}
public void onLocationChanged(Location location) {
if (location != null){
GPSData = location.getLatitude() + "," +
location.getLongitude();
Log.v(LTAG, "GPS data received ===========> " +
GPSData);
}
else
Log.v(LTAG, "Location is null ===========> ");
}
};
public String getCurrentData() {
return GPSData;
}
public void setContext(Context context) {
myContext = context;
}
public boolean startSensing() {
if (myContext == null){
Log.w(LTAG, "myContext not set");
return false;
}
Log.v(LTAG, "Starting location updates !");
lMgr = (LocationManager)
myContext.getSystemService(Context.LOCATION_SERVICE);
lMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,
myLocListener);
//lMgr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER,
0,
0, myLocListener);
Log.v(LTAG, "Registered myLocListener for GPS");
return true;
}
public boolean stopSensing() {
if (myContext == null){
Log.w(LTAG, "myContext not set");
return false;
}
Log.v(LTAG, "Stopping location updates !");
lMgr.removeUpdates(myLocListener);
return false;
}
}//GPSSensor
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en