0

I am trying to show my location on a GoogleMap but Android Studio reports a fatal error on the following line

savedGoogleMap.isMyLocationEnabled = true

The error message is

Missing permissions required by GoogleMap.setMyLocationEnabled: android.permission.ACCESS_COARSE_LOCATION or android.permission.ACCESS_FINE_LOCATION

The problem is the manifest file already includes both permissions so they are not missing!

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Using the IDE context actions to add the permissions inserts additional .ACCESS___LOCATION to the manifest file but Android Studio still reports the fatal error

The apparent issue is Android Studio is ignoring permissions included in the manifest

Earlier posts e.g. here highlight the need for runtime permission checks

My App checks for the required permissions and if checkSelfPermission is not granted I then request the required permissions

if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)

So at this moment my app shows a fatal error but there appears no way to fix it

Can anyone suggest other avenues I might try ?

Update

Despite the fatal error the App builds and launches? It also shows myLocation on the Google map.

RatherBeSailing
  • 261
  • 1
  • 11
  • Request the permissions separately. Sequence matters. – blackapps Oct 27 '22 at 07:27
  • @blackapps thank you for your reply - I tried deleting the two uses-permission and then allowing Android Studio to insert them into the manifest file - but does not fix the issue. I therefore tried adding them in the reverse order - also no luck. Perhaps I did not understand what you meant by "sequence matters" ? – RatherBeSailing Oct 28 '22 at 00:53
  • Just put both in the manifest file. There the sequence does not matter. But then at runtime you have to execute code to let the user confirm those permissions. Then the sequence matters. One by one. Runtime permissions. – blackapps Oct 28 '22 at 06:07
  • @blackapps thank you for the clarification and I admire anyone patient enough to fight their way through permissions but I have never had an issue with asking for multiple permissions at the same time e.g. . The shown error claims I have not added the permissions - it is not claiming I need to add a runtime check of the permissions. Since I have already added the permissions there remains no way to remove the (incorrectly reported) error – RatherBeSailing Oct 28 '22 at 23:57

1 Answers1

0

My problem is the manifest file already includes both permissions!

That's not the problem. It is totally fine to have both permissions declared in your AndroidManifest.xml file, just make sure they are added in the correct place like so declaring permissions

After you double checked on that one, make sure you you not only call checkSelfPermission, but also requestPermissions like this: requesting permissions

After receiving the result proceed with your calls (or if the permission was already granted).

If you are positive with this so far and still no success, it would seem to me that something else is causing the problem and I would look into the configuration files, library dependency, caches etc.

Kostek
  • 283
  • 3
  • 10
  • thank you for your detailed and 100% correct response - I apologise my use of "issue" was ambiguous so I have updated the post to clarify the "problem" is adding and checking the permissions does not fix the fatal error. However my update also clarifies despite the reported error(s) the app builds and runs correctly. – RatherBeSailing Nov 26 '22 at 04:54