Android Question App crash when add googlemap to AHViewPager with Tablayout ?

pmt

Member
Licensed User
Hi everyone,

I have created the app by follow Erel 's googlemap v2 tutorial and worked!!.

I want to add googlemap v2 to Corwin 's AHViewPager but It 's not work the app crash at run time.

I try theses steps
1.Create app base on Corwin's NavigatoinView1_0.zip sample project.
from this link https://www.b4x.com/android/forum/threads/designsupport-additional-material-design-components.58893/

I added google play service configurations to manifest and include all jars and resources in activity.

2.add 3 panels to the Page Container
B4X:
Sub Activity_Create(FirstTime As Boolean)

...
Dim pn1 As Panel
Dim pn2 As Panel
Dim pnMap As Panel

pn1 .Initialize("")
pn2 .Initialize("")
pnMap .Initialize("")  
'if  I   load  map layout here the app crash at first run time then I will load later at VP_PageCreated  event

'there are 3 pages
PC.AddPage(pn1, "page1") 'empty page
PC.AddPage(pn2, "page2") 'empty page
PC.AddPage(pnMap, "page3") 'empty page
...
End Sub

3.Load Map Layout
B4X:
Sub VP_PageCreated (Position As Int, Page As Object)

Dim pn As Panel
        If Position =2 Then 'page 3 for  map
            pn = Page
            pn.LoadLayout("mymap")
        End If

End Sub

4.run the app
the app crash when change page from page 1 to page 2
==============
--------- beginning of crash
--------- beginning of main
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
PageCreated: 0
PageCreated: 1
StateChange: 1
StateChange: 2
PageChanged: 1
PageCreated: 2
StateChange: 0
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:387)
at gl.bcom.google.android.gms.DynamiteModulesB:20)
at com.google.android.gms.maps.internal.bf.acom.google.android.gms.DynamiteModulesB:5)
at com.google.maps.api.android.lib6.impl.bb.runcom.google.android.gms.DynamiteModulesB:5)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5452)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:762)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:652)
Caused by: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
at com.google.maps.api.android.lib6.impl.az.ccom.google.android.gms.DynamiteModulesB:675)
at com.google.android.gms.maps.internal.k.onTransactcom.google.android.gms.DynamiteModulesB:141)
at android.os.Binder.transact(Binder.java:387)
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



==============
I try to solve the problem but I can't.

Regards,
 

DonManfred

Expert
Licensed User
Longtime User
Based on the error

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)

you maybe have set the manifest incorrectly.
Check and compare the manifest with the googlemaps example which is working.

Upload a small project which shows the issue
 
Upvote 0

pmt

Member
Licensed User
Check and compare the manifest with the googlemaps example which is working.
I didn't find something wrong I copy and paste the manifest from the app which is working.

My guess is that you set the targetSdkVersion to 23+ and haven't requested the location permission at runtime.
I don't know why but I don't need to requested the location permission at runtime , I use <uses-sdk android:minSdkVersion="15" android:targetSdkVersion="25"/> in manifest for the app which is working.

However now it 's working but I don't know why , I do nothing .Surprise !!

May be the problem from google map api or my android phone.

I will check later ,why does it work ?


Thank you very much.
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
android:targetSdkVersion="25"
Starting with android api 23 you need to USE Runtimepermissionslib and request permissions at runtime.


I just see the link is no longer existent...

See here for the List of dangerous Permissions: https://developer.android.com/guide/topics/permissions/requesting.html#perm-groups

ACCESS_FINE_LOCATION is one of these permissions you need to use Runtimepermissions Library to request the permission for.
 
Last edited:
Upvote 0

pmt

Member
Licensed User
Starting with android api 23 you need to USE Runtimepermissionslib and request permissions at runtime.

I confirm , I use < android:targetSdkVersion="25" > and it work without use Runtimepermissionslib and request permissions at runtime.

I test on Lollipop and Marshmallow.

Regards,
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
and it work without use Runtimepermissionslib and request permissions at runtime.

java.lang.RuntimeException: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION
Looks like it does not work without using Runtimepermissionslib...
 
Upvote 0

pmt

Member
Licensed User
Now my app work without crash as my answer at reply#4 .
However now it 's working but I don't know why , I do nothing .Surprise !!

However for security reason I agree with you I should request the permission at runtime.

Regards,
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…