Reputation: 10039
I write this code to receive location updates -
PendingIntent launchIntent = PendingIntent.getBroadcast(context, 5000, intent, 0);
manager.requestLocationUpdates(selectProvider(), 0, 0, launchIntent);
I select the gps provider if its available, otherwise the network provider. Is there a way I could switch back to the gps one if it gets enabled later?
Does the system broadcast an intent when gps provider is enabled or disabled? Could I set up a listener for the same?
Upvotes: 3
Views: 6939
Reputation: 80340
You can detect if GPS status changed, e.g. if a GPS satellite fix was acquired.
Look at GpsStatus.Listener
. Register it with locationManager.addGpsStatusListener(gpsStatusListener)
.
Upvotes: 7
Reputation: 7754
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
public void onProviderEnabled(String provider) {
Toast.makeText(this, "Enabled new provider " + provider,
Toast.LENGTH_LONG).show();
}
public void onProviderDisabled(String provider) {
Toast.makeText(this, "GPS disconnected", Toast.LENGTH_LONG);
Toast.makeText(getApplicationContext(), "Connected",
Toast.LENGTH_LONG);
Toast.makeText(this, "Please Switch on GPS." + provider,
Toast.LENGTH_LONG).show();
}
Upvotes: 5