Improving the User Experience When Using GPS Location

Using the information you have discovered, you’ll now make the On Your Bike app a bit more robust. You’ll tell the user when GPS is turned off and will turn it on when required.

1. Open the WhereAmI class. You can find out a little more about the state of the GPS by adding a GPS status listener. In the startSearching method, just after requesting the location update, call addGpsStatusListener. Run Quick fix to implement the Listener interface, and run Quick fix again to add the onGpsStatusChanged method (see Listing 7.16).

Listing 7.16 Listening for Changes to the GPS Status

if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {    locationManager ...

Get Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.