The Last Known Location - Don't get the broadcast


I turned off the TestProvider and clicked the Start button. I expected both of the LocationReceiver.onReceive() methods to get the broadcast sent by RunManager, but neither does. I thought this was how the GPS service would broadcast its location updates.

On the emulator, lastKnown = null. So, I modified RunManager with code from TestProvider:

[code] public void startLocationUpdates() {
String provider = LocationManager.GPS_PROVIDER;

	// If you have the test provider and it's enabled, use it
	if (mLocationManager.getProvider(TEST_PROVIDER) != null && mLocationManager.isProviderEnabled(TEST_PROVIDER)) {
		provider = TEST_PROVIDER;
	Log.d(TAG, "Using provider " + provider);

	// Get the last known location and broadcast it if you have one
	Location lastKnown = mLocationManager.getLastKnownLocation(provider);
	if (lastKnown != null) {
		// Reset the time to now
	} else {
		lastKnown = new Location(provider);

	// Start updates from the location manager
	PendingIntent pi = getLocationPendingIntent(true);
	mLocationManager.requestLocationUpdates(provider, 5000, 0, pi);

But this doesn’t work if I use TestProvider or not.

OOPS![/size][/color] Gotta put the code to send the broadcast BELOW the code to “requestLocationUpdates”. Now it works.


Glad you found the fix!

Make sure you’re able to get a fix when you use the GPS provider, by the way. You can subscribe to it and it’ll just sit there when you’re inside, not being able to do anything.