sdixon Member Licensed User Longtime User Jun 23, 2016 #1 I am building a gps app but a can't seem to get the run time permissions right. Is there a best practice in how to use them? I added this to the Activity_Create Code: rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION) and this to the manifest Code: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in the Activity_PermissionResult Code: Sub Activity_PermissionResult (Permission As String, Result As Boolean) If Permission = rp.PERMISSION_ACCESS_COARSE_LOCATION Then Result = True End If End Sub but when it goes through the Activity_resume where this code is placed Code: If (Starter.nfpGPS.GPSEnabled) Then Starter.nfpGPS.Start(0, 0) 'Listen to GPS with no filters. Else ToastMessageShow(Starter.nfpEnableGPS, True) StartActivity(Starter.nfpGPS.LocationSettingsIntent) 'Will open the relevant settings screen. End If I get an error telling me that I need the android.permission.ACCESS_FINE_LOCATION I am obviously doing something wrong, but I can't figure it out. Thanks
I am building a gps app but a can't seem to get the run time permissions right. Is there a best practice in how to use them? I added this to the Activity_Create Code: rp.CheckAndRequest(rp.PERMISSION_ACCESS_FINE_LOCATION) and this to the manifest Code: <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in the Activity_PermissionResult Code: Sub Activity_PermissionResult (Permission As String, Result As Boolean) If Permission = rp.PERMISSION_ACCESS_COARSE_LOCATION Then Result = True End If End Sub but when it goes through the Activity_resume where this code is placed Code: If (Starter.nfpGPS.GPSEnabled) Then Starter.nfpGPS.Start(0, 0) 'Listen to GPS with no filters. Else ToastMessageShow(Starter.nfpEnableGPS, True) StartActivity(Starter.nfpGPS.LocationSettingsIntent) 'Will open the relevant settings screen. End If I get an error telling me that I need the android.permission.ACCESS_FINE_LOCATION I am obviously doing something wrong, but I can't figure it out. Thanks
Erel B4X founder Staff member Licensed User Longtime User Jun 23, 2016 #2 You don't need to add anything to the manifest editor as the permission is added automatically. Your code checks for the COARSE permission no the FINE permission. Upvote 0
You don't need to add anything to the manifest editor as the permission is added automatically. Your code checks for the COARSE permission no the FINE permission.
sdixon Member Licensed User Longtime User Jun 23, 2016 #3 Sorry, it checked for both and I deleted the wrong one. Having said that, and changing it I get the following error message when it hits this line of code Code: Starter.nfpGPS.Start(0, 0) 'Listen to GPS with no filters. Code: Installing file. PackageAdded: package:com.unicornsystemz.perfect_parking Copying updated assets files (33) ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** Error occurred on line: 181 (Main) java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission. at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:688) at android.location.LocationManager.requestLocationUpdates(LocationManager.java:908) at android.location.LocationManager.requestLocationUpdates(LocationManager.java:469) at anywheresoftware.b4a.gps.GPS.Start(GPS.java:117) at com.unicornsystemz.perfect_parking.main._activity_resume(main.java:795) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at com.unicornsystemz.perfect_parking.main.afterFirstLayout(main.java:103) at com.unicornsystemz.perfect_parking.main.access$000(main.java:18) at com.unicornsystemz.perfect_parking.main$WaitForLayout.run(main.java:81) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Thanks Upvote 0
Sorry, it checked for both and I deleted the wrong one. Having said that, and changing it I get the following error message when it hits this line of code Code: Starter.nfpGPS.Start(0, 0) 'Listen to GPS with no filters. Code: Installing file. PackageAdded: package:com.unicornsystemz.perfect_parking Copying updated assets files (33) ** Service (starter) Create ** ** Service (starter) Start ** ** Activity (main) Create, isFirst = true ** Error occurred on line: 181 (Main) java.lang.SecurityException: "gps" location provider requires ACCESS_FINE_LOCATION permission. at android.os.Parcel.readException(Parcel.java:1620) at android.os.Parcel.readException(Parcel.java:1573) at android.location.ILocationManager$Stub$Proxy.requestLocationUpdates(ILocationManager.java:688) at android.location.LocationManager.requestLocationUpdates(LocationManager.java:908) at android.location.LocationManager.requestLocationUpdates(LocationManager.java:469) at anywheresoftware.b4a.gps.GPS.Start(GPS.java:117) at com.unicornsystemz.perfect_parking.main._activity_resume(main.java:795) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:703) at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:340) at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:247) at java.lang.reflect.Method.invoke(Native Method) at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:134) at com.unicornsystemz.perfect_parking.main.afterFirstLayout(main.java:103) at com.unicornsystemz.perfect_parking.main.access$000(main.java:18) at com.unicornsystemz.perfect_parking.main$WaitForLayout.run(main.java:81) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Thanks
DonManfred Expert Licensed User Longtime User Jun 23, 2016 #4 sdixon said: Sorry, it checked for both and I deleted the wrong one. Click to expand... looks like you are still using the COARSE permisson, not the FINE permission (which is expected) Upvote 0
sdixon said: Sorry, it checked for both and I deleted the wrong one. Click to expand... looks like you are still using the COARSE permisson, not the FINE permission (which is expected)
Erel B4X founder Staff member Licensed User Longtime User Jun 23, 2016 #5 I've updated the GPS tutorial: https://www.b4x.com/android/forum/threads/gps-tutorial.6592/ Upvote 0
sdixon Member Licensed User Longtime User Jun 23, 2016 #6 I followed the updated tutorial to the letter but now I get the following. When I start the app for the first time everything loads but when it goes to check the permission with a java error of Code: Installing file. PackageAdded: package:com.unicornsystemz.perfect_parking Copying updated assets files (33) ** 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.MapFragment$zza$1.zza(Unknown Source) at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source) at android.os.Binder.transact(Binder.java:387) at wv.a(:com.google.android.gms.DynamiteModulesB:82) at maps.ag.t$5.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION at maps.ag.t.c(Unknown Source) at uz.onTransact(:com.google.android.gms.DynamiteModulesB:274) at android.os.Binder.transact(Binder.java:387) at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.setMyLocationEnabled(Unknown Source) at com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(Unknown Source) at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:183) ... 12 more the problem seems to be in at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196) when I click away the app has stopped dialog I get the following, which I expect and if I accept the permission, the app starts up as designed, but it would be nice if it started up right the first time. I have made the changes to the manifest and added Code: #AdditionalJar: com.google.android.gms:play-services-maps Thanks Upvote 0
I followed the updated tutorial to the letter but now I get the following. When I start the app for the first time everything loads but when it goes to check the permission with a java error of Code: Installing file. PackageAdded: package:com.unicornsystemz.perfect_parking Copying updated assets files (33) ** 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.MapFragment$zza$1.zza(Unknown Source) at com.google.android.gms.maps.internal.zzo$zza.onTransact(Unknown Source) at android.os.Binder.transact(Binder.java:387) at wv.a(:com.google.android.gms.DynamiteModulesB:82) at maps.ag.t$5.run(Unknown Source) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:158) at android.app.ActivityThread.main(ActivityThread.java:7229) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120) Caused by: java.lang.SecurityException: my location requires permission ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION at maps.ag.t.c(Unknown Source) at uz.onTransact(:com.google.android.gms.DynamiteModulesB:274) at android.os.Binder.transact(Binder.java:387) at com.google.android.gms.maps.internal.IGoogleMapDelegate$zza$zza.setMyLocationEnabled(Unknown Source) at com.google.android.gms.maps.GoogleMap.setMyLocationEnabled(Unknown Source) at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:183) ... 12 more the problem seems to be in at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196) when I click away the app has stopped dialog I get the following, which I expect and if I accept the permission, the app starts up as designed, but it would be nice if it started up right the first time. I have made the changes to the manifest and added Code: #AdditionalJar: com.google.android.gms:play-services-maps Thanks
sdixon Member Licensed User Longtime User Jun 23, 2016 #7 Thanks for all your help. Code: at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196) I put the mapFragment in question into it's own layout, which was then loaded after the permissions were sorted out Code: Sub Activity_PermissionResult (Permission As String, Result As Boolean) If Permission = Starter.rp.PERMISSION_ACCESS_FINE_LOCATION Then If Result Then CallSub(Starter, "StartGPS") Init_GoogleMaps End If End If End Sub and then everything works as designed. Upvote 0
Thanks for all your help. Code: at anywheresoftware.b4a.objects.MapFragmentWrapper$1.onMapReady(MapFragmentWrapper.java:196) I put the mapFragment in question into it's own layout, which was then loaded after the permissions were sorted out Code: Sub Activity_PermissionResult (Permission As String, Result As Boolean) If Permission = Starter.rp.PERMISSION_ACCESS_FINE_LOCATION Then If Result Then CallSub(Starter, "StartGPS") Init_GoogleMaps End If End If End Sub and then everything works as designed.