Hi, I had a service in Starter Module which will run after every 1 minute to get the current location. When the application first run it crashes on asking for permission. After allowing it next time it runs OK. I understand the the permission need to place first but how? Where did I do wrong ? Below is my code
In Main Activity Module
In Starter Service
And the crash report below
FusedLocationProvider1_ConnectionSuccess
Error occurred on line: 159 (Starter)
java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzcda.zza(Unknown Source)
at com.google.android.gms.internal.zzcdd.zza(Unknown Source)
at com.google.android.gms.internal.zzcdj.zza(Unknown Source)
at com.google.android.gms.internal.zzccc.zza(Unknown Source)
at com.google.android.gms.internal.zzbay.zzb(Unknown Source)
at com.google.android.gms.internal.zzbca.zze(Unknown Source)
at com.google.android.gms.internal.zzbcx.zze(Unknown Source)
at com.google.android.gms.internal.zzbcp.zze(Unknown Source)
at com.google.android.gms.internal.zzccb.requestLocationUpdates(Unknown Source)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.RequestLocationUpdates(FusedLocationProviderWrapper.java:202)
at com.bmc.coreBMCApp.starter._fusedlocationprovider1_connectionsuccess(starter.java:380)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProvider.onConnected(FusedLocationProvider.java:64)
at com.google.android.gms.common.internal.zzac.zzn(Unknown Source)
at com.google.android.gms.internal.zzbcp.zzm(Unknown Source)
at com.google.android.gms.internal.zzbcd.zzpY(Unknown Source)
at com.google.android.gms.internal.zzbcd.onConnected(Unknown Source)
at com.google.android.gms.internal.zzbcx.onConnected(Unknown Source)
at com.google.android.gms.internal.zzbbi.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzaa.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzn.zzrj(Unknown Source)
at com.google.android.gms.common.internal.zze.zzs(Unknown Source)
at com.google.android.gms.common.internal.zzi.zzrk(Unknown Source)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:231)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:399)
at com.bmc.coreBMCApp.main._ping(main.java:1251)
at com.bmc.coreBMCApp.main._getdevstat(main.java:1106)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at com.bmc.coreBMCApp.main.afterFirstLayout(main.java:102)
at com.bmc.coreBMCApp.main.access$000(main.java:17)
at com.bmc.coreBMCApp.main$WaitForLayout.run(main.java:80)
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:5451)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thank you in advance ...
In Main Activity Module
B4X:
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
'Activity.LoadLayout("Layout1")
If FirstTime Then
Starter.reqForPerm.CheckAndRequest(Starter.reqForPerm.PERMISSION_SEND_SMS)
Starter.reqForPerm.CheckAndRequest(Starter.reqForPerm.PERMISSION_ACCESS_FINE_LOCATION)
End If
End Sub
In Starter Service
B4X:
Sub Process_Globals
Private FusedLocationProvider1 As FusedLocationProvider
Public LastLocation As Location
End Sub
Sub Service_Create
'This is the program entry point.
'This is a good place to load resources that are not specific to a single activity.
FusedLocationProvider1.Initialize("FusedLocationProvider1")
End Sub
Sub Service_Start (StartingIntent As Intent)
StartServiceAt("", DateTime.Now + 30 * DateTime.TicksPerSecond, True) 'schedule the next task to run in 30 seconds.
If Not(IsPaused("Starter")) Then
If FusedLocationProvider1.IsConnected = False Then
FusedLocationProvider1.Connect
End If
End If
End Sub
And the crash report below
FusedLocationProvider1_ConnectionSuccess
Error occurred on line: 159 (Starter)
java.lang.SecurityException: Client must have ACCESS_FINE_LOCATION permission to request PRIORITY_HIGH_ACCURACY locations.
at android.os.Parcel.readException(Parcel.java:1620)
at android.os.Parcel.readException(Parcel.java:1573)
at com.google.android.gms.internal.zzed.zzb(Unknown Source)
at com.google.android.gms.internal.zzcda.zza(Unknown Source)
at com.google.android.gms.internal.zzcdd.zza(Unknown Source)
at com.google.android.gms.internal.zzcdj.zza(Unknown Source)
at com.google.android.gms.internal.zzccc.zza(Unknown Source)
at com.google.android.gms.internal.zzbay.zzb(Unknown Source)
at com.google.android.gms.internal.zzbca.zze(Unknown Source)
at com.google.android.gms.internal.zzbcx.zze(Unknown Source)
at com.google.android.gms.internal.zzbcp.zze(Unknown Source)
at com.google.android.gms.internal.zzccb.requestLocationUpdates(Unknown Source)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProviderWrapper.RequestLocationUpdates(FusedLocationProviderWrapper.java:202)
at com.bmc.coreBMCApp.starter._fusedlocationprovider1_connectionsuccess(starter.java:380)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
at uk.co.martinpearman.b4a.fusedlocationprovider.FusedLocationProvider.onConnected(FusedLocationProvider.java:64)
at com.google.android.gms.common.internal.zzac.zzn(Unknown Source)
at com.google.android.gms.internal.zzbcp.zzm(Unknown Source)
at com.google.android.gms.internal.zzbcd.zzpY(Unknown Source)
at com.google.android.gms.internal.zzbcd.onConnected(Unknown Source)
at com.google.android.gms.internal.zzbcx.onConnected(Unknown Source)
at com.google.android.gms.internal.zzbbi.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzaa.onConnected(Unknown Source)
at com.google.android.gms.common.internal.zzn.zzrj(Unknown Source)
at com.google.android.gms.common.internal.zze.zzs(Unknown Source)
at com.google.android.gms.common.internal.zzi.zzrk(Unknown Source)
at com.google.android.gms.common.internal.zzh.handleMessage(Unknown Source)
at android.os.Handler.dispatchMessage(Handler.java:102)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:231)
at anywheresoftware.b4a.Msgbox.waitForMessage(Msgbox.java:200)
at anywheresoftware.b4a.keywords.Common.DoEvents(Common.java:399)
at com.bmc.coreBMCApp.main._ping(main.java:1251)
at com.bmc.coreBMCApp.main._getdevstat(main.java:1106)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:710)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:342)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:249)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:139)
at com.bmc.coreBMCApp.main.afterFirstLayout(main.java:102)
at com.bmc.coreBMCApp.main.access$000(main.java:17)
at com.bmc.coreBMCApp.main$WaitForLayout.run(main.java:80)
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:5451)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Thank you in advance ...