1

If GPS is NOT turned on, my code prompts the user and I get the location updates (as expected)

However if GPS is already turned on, I donot get location updates. I can see my start() method getting called in logcat, but I dont see update() method getting called.

private static final long MIN_UPDATE_DISTANCE = 6;
private static final String TAG =  LocationTracker.class.getSimpleName();
// The minimum time between updates in milliseconds
private static final long MIN_UPDATE_TIME = 1000 * 1;//==update every 1 seconds
    ....
public void start(){
    Log.e(TAG, "start");
    lm = (LocationManager) MyApp.getAppContext().getSystemService(Context.LOCATION_SERVICE);//let's see if getting LM again helps
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, MIN_UPDATE_TIME, MIN_UPDATE_DISTANCE, this);

    return;
}



public void onLocationChanged(Location newLoc) { 
        Log.e(TAG, "onLocationChanged");
}

EDIT

public static boolean isLocationServicesEnabled(){
        Log.e(TAG,"isLocationServicesEnabled");
        String locationProvider = Settings.Secure.getString(
                MyApp.getAppContext().getContentResolver(),
                Settings.Secure.LOCATION_PROVIDERS_ALLOWED);//note: this is deprecated

        if (locationProvider == null || locationProvider.equalsIgnoreCase("")) {

            return false;
        } 
        return true;


}


public void stop(){        
        Log.e(TAG,"stopping GPS");
        lm.removeUpdates(this);
        isRunning = false;
        listener = null;
        lm = null;

}

Here is how I am calling them:

if(isLocationServicesEnabled){
         stop();
         start()
}

Here is the snippet from gradle

android {
compileSdkVersion 21
buildToolsVersion "21.1.2"

defaultConfig {
    applicationId "com.XX.XX.main"
    minSdkVersion 19
    targetSdkVersion 21
    versionCode 15

}   
mobileDev
  • 1,358
  • 2
  • 14
  • 34

0 Answers0