Android Question Google maps and security exemptions on android 7

mcqueccu

Well-Known Member
Licensed User
I followed the google maps integration process, and it works well on my samsung galaxy trend (kitkat) but gives the following error on my Moto C Plus (Nougat 7.0)

This is my manifest, and the the permission being used are in the picture attached.

B4X:
AddApplicationText(
   <activity android:name="com.google.android.gms.common.api.GoogleApiActivity"
  android:theme="@android:style/Theme.Translucent.NoTitleBar"
  android:exported="false"/>
    <meta-data
  android:name="com.google.android.gms.version"
  android:value="@integer/google_play_services_version" />
)
'************ Google Play Services Base (end) ************

'************ Google Maps ************
AddApplicationText(
<meta-data
  android:name="com.google.android.geo.API_KEY"
  android:value="AIzaxxxxx my api key insertedxxxx"/>
)

'************ Google Maps end************

B4X:
--------- beginning of crash
--------- beginning of system
--------- beginning of main
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
java.lang.RuntimeException: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
    at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196)
    at com.google.android.gms.maps.zzaa.zza(Unknown Source)
    at com.google.android.gms.maps.internal.zzaq.onTransact(Unknown Source)
    at android.os.Binder.transact(Binder.java:504)
    at er.b(:com.google.android.gms.DynamiteModulesB@11951436:20)
    at com.google.android.gms.maps.internal.bf.a(:com.google.android.gms.DynamiteModulesB@11951436:5)
    at com.google.maps.api.android.lib6.impl.bc.run(:com.google.android.gms.DynamiteModulesB@11951436:5)
    at android.os.Handler.handleCallback(Handler.java:836)
    at android.os.Handler.dispatchMessage(Handler.java:103)
    at android.os.Looper.loop(Looper.java:203)
    at android.app.ActivityThread.main(ActivityThread.java:6251)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1075)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
Caused by: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
    at com.google.maps.api.android.lib6.impl.ba.c(:com.google.android.gms.DynamiteModulesB@11951436:684)
    at com.google.android.gms.maps.internal.k.onTransact(:com.google.android.gms.DynamiteModulesB@11951436:141)
    at android.os.Binder.transact(Binder.java:504)
    at com.google.android.gms.internal.zzed.zzb(Unknown Source)
    at com.google.android.gms.maps.internal.zzg.setMyLocationEnabled(Unknown Source)
    at com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(Unknown Source)
    at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:183)
    ... 13 more
 

Attachments

  • maps.png
    maps.png
    10 KB · Views: 383

mcqueccu

Well-Known Member
Licensed User
I have added the RuntimePermission lib and the necessary codes but strangely, the apps still crash with same error message. It doesnt give me the notification to allow permssion. Here is my code


B4X:
Sub Process_Globals
    Dim rp As RuntimePermissions
End Sub

Sub Globals
    Private gmap As GoogleMap
    Private MapFragment1 As MapFragment   
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    
    If MapFragment1.IsGooglePlayServicesAvailable = False Then
        ToastMessageShow("Please install Google Play Services.", True)
    End If   
End Sub

Sub MapFragment1_Ready
    gmap = MapFragment1.GetMap   
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
       Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
       m1.Snippet = "This is the snippet"   
End Sub

Sub Activity_PermissionResult (Permission As String, Result As Boolean)
    If Permission = rp.PERMISSION_ACCESS_FINE_LOCATION Then
        gmap.MyLocationEnabled = Result
    End If   
End Sub
 
Upvote 0

Erel

Administrator
Staff member
Licensed User
Disable the location in the designer and enable it once you have the permission:
B4X:
Sub MapFragment1_Ready
    gmap = MapFragment1.GetMap   
    rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION)
    Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
     gmap.MyLocationEnabled = Result
       Dim m1 As Marker = gmap.AddMarker(10, 30, "test")
       m1.Snippet = "This is the snippet"   
End Sub
 
Upvote 0
Top