Android Question Problem with Google Maps with FusedLocationProvider

JMB

Active Member
Licensed User
Longtime User
Hi there,

I am trying to get the Demo code for the Fused Location Provider to work.

I have put my GEO API key in, and I have added
B4X:
AddPermission(android.permission.ACCESS_FINE_LOCATION)

to the manifest but I get a java Security Exception telling that my location requires ACCESS_FINE_LOCATION.

I am a bit stumped as to how to add this, as I thought adding the permission to the manifest would do it.

Can anyone shed some light?

Thank you.

JMB
 

JMB

Active Member
Licensed User
Longtime User
Thank you, Emexes and Bill - all very useful. I continue to stagger towards success.

However, I am a little confused. I have looked at various pieces of code and the tutorial, and I can't figure out why this piece of code doesn't pop up a dialog asking for permission for use of location? It just sits and does nothing.

B4X:
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        Log("Got FINE LOCATION")
    Else
        Log("didn't get permission")
    End If
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Did you added the permission to the manifest too?
Best is to upload a sampleproject which shows the issue.

Edit to add: and you are targeting sdk 23+?
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="16" android:targetSdkVersion="28"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
 
Last edited:
Upvote 0

JMB

Active Member
Licensed User
Longtime User
Ah, thank you Manfred and others.

I didn't realise that one had to add the permission to the manifest. Adding that in caused the dialog asking for permission to access location to show.

What is rather strange is that I tried some code which Erel put up in the tutorial and that appeared to work without asking for the permission in the manifest

Specifically, this was the code that worked without a permission in the manifest:

B4X:
    rp.CheckAndRequest(rp.PERMISSION_READ_PHONE_STATE)
   
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
    If Result Then
        Dim pid As PhoneId
        Log(pid.GetDeviceId)
    Else
        Log("didn't get permission")
    End If

When I ran this, it popped the dialog up with no problem, and yet it is listed as a "Dangerous" permission in the same way that Location access is considered "Dangerous".

How can one tell which permissions need to be in the Manifest, and which permissions don't? Or should I just put all the permissions that I need in the manifest, along with the rp.CheckAndReqest code?

Thanks to all for your help.

JMB
 
Upvote 0
Top