Skip to content

Commit

Permalink
Handle unavailable coarse location provider; fixes #42
Browse files Browse the repository at this point in the history
  • Loading branch information
bilde2910 committed Oct 16, 2019
1 parent c141707 commit 277a24b
Showing 1 changed file with 17 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,7 @@ public void onLocationChanged(Location location) {
}
};

Log.i("Requesting location updates from device location services"); //NON-NLS
this.locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, this.share.getSession().getIntervalMillis(), 0.0F, this.listenCoarse);
this.locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, this.share.getSession().getIntervalMillis(), 0.0F, this.listenFine);
attachToLocationServices();
} else {
Log.e("Location permission that was granted earlier has been rejected - sharing aborted"); //NON-NLS
}
Expand All @@ -163,6 +161,22 @@ public void onDestroy() {
super.onDestroy();
}

/**
* Attaches the listeners to the location manager to request updates.
*
* @throws SecurityException If location permission is missing.
*/
private void attachToLocationServices() throws SecurityException {
Log.i("Requesting location updates from device location services"); //NON-NLS
try {
this.locMan.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, this.share.getSession().getIntervalMillis(), 0.0F, this.listenCoarse);
} catch (IllegalArgumentException ex) {
Log.w("Coarse location provider does not exist!", ex); //NON-NLS
this.listenCoarse = null;
}
this.locMan.requestLocationUpdates(LocationManager.GPS_PROVIDER, this.share.getSession().getIntervalMillis(), 0.0F, this.listenFine);
}

/**
* Called when either the coarse or the fine location provider has received a location update.
* Pushes the location update to the session backend.
Expand Down

0 comments on commit 277a24b

Please sign in to comment.