For this chapter, I’m using my device and not an emulator, and I’m also using Android Studio 3.0 Canary 3. All the code works great except this part gives me error if I don’t put it in try/catch with SecurityException:
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "Got a fix: " + location);
new SearchTask().execute(location);
}
});
Code now reads:
if (hasLocationPermission()) {
try {
LocationServices.FusedLocationApi
.requestLocationUpdates(mClient, request, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
Log.i(TAG, "Got a fix: " + location);
//Now that you have a location fix, use it.
// Asynctask find GalleryItem near your location
// fix, download its associated image, and display it
new SearchTask().execute(location);
}
});
} catch (SecurityException ex) {
Log.e(TAG, "Error creating location service: " + ex.getMessage());
}
}