Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1

Chapter 33  Locations and Play Services


Run your app and press the search button. Sadly, your dramatic red error indicator will come due when
your app runs: You will see a message indicating that Locatr has stopped (Figure 33.8).


Figure 33.8  Permission: denied


If you check Logcat, you will see that a SecurityException was thrown:


FATAL EXCEPTION: main
Process: com.bignerdranch.android.locatr, PID: 7892
java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to
request PRIORITY_HIGH_ACCURACY locations.
at android.os.Parcel.readException(Parcel.java:1684)
at android.os.Parcel.readException(Parcel.java:1637)
...
at com.google.android.gms.location.internal.zzd
.requestLocationUpdates(Unknown Source)
at com.bignerdranch.android.locatr.LocatrFragment
.findImage(LocatrFragment.java:102)
at com.bignerdranch.android.locatr.LocatrFragment
.onOptionsItemSelected(LocatrFragment.java:89)
at android.support.v4.app.Fragment.performOptionsItemSelected(Fragment.java:2212)
...
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller
.run(ZygoteInit.java:886)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:776)


For your call to requestLocationUpdates(...) to work, you must first ask permission.

Free download pdf