Android Question android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_COARSE_LOCATION

davemorris

Active Member
Licensed User
Longtime User
Hi Can someone help

Up to a few hours ago code worked great and now it crashes

with
Successfully connected to location services. Getting last known location...
Error occurred on line: 250 (clsLocation)
java.lang.SecurityException: uid 10535 does not have any of [android.permission.ACCESS_FINE_LOCATION, android.permission.ACCESS_COARSE_LOCATION].
at android.os.Parcel.createException(Parcel.java:2071)
at android.os.Parcel.readException(Parcel.java:2039)
at android.os.Parcel.readException(Parcel.java:1987)
at com.google.android.gms.internal.location.zza.zzc(com.google.android.gms:play-services-location@@21.0.0:3)
at com.google.android.gms.internal.location.zzn.zzk(com.google.android.gms:play-services-location@@21.0.0:5)
at com.google.android.gms.internal.location.zzda.zzv(com.google.android.gms:play-services-location@@21.0.0:15)
at com.google.android.gms.internal.location.zzak.doExecute(com.google.android.gms:play-services-location@@21.0.0:3)
at com.google.android.gms.common.api.internal.BaseImplementation$ApiMethodImpl.run(com.google.android.gms:play-services-base@@18.1.0:1)
at com.google.android.gms.common.api.internal.zaaj.zab(com.google.android.gms:play-services-base@@18.1.0:6)
at com.google.android.gms.common.api.internal.zabi.zaf(com.google.android.gms:play-services-base@@18.1.0:2)
at com.google.android.gms.common.api.internal.zabe.execute(com.google.android.gms:play-services-base@@18.1.0:12)
at com.google.android.gms.internal.location.zzau.requestLocationUpdates(com.google.android.gms:play-services-location@@21.0.0:11)

To me this would suggestion a problem with the permissions in the manifest file - see below (line 40 has the permission)

Manifest file:
'This code will be applied to the manifest file during compilation.
'You do not need to modify it in most cases.
'See this link for for more information: https://www.b4x.com/forum/showthread.php?p=78136
AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="33"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
    
' Include to deal with problems with keyboard hidding part of Stripe payment page.
'SetActivityAttribute(aCardEntry, android:windowSoftInputMode, adjustResize|stateHidden)
    
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
' This line added for notification exp - otherwise a "Generating R file.    Error" occurred.
CreateResourceFromFile(Macro, Themes.DarkTheme)
'End of default text.

' These lines added for notification exp
'************ Required with GetSafeDirDefaultExternal ***********
AddManifestText(<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)

' Added for Firebase
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase)
CreateResourceFromFile(Macro, FirebaseAnalytics.Firebase)
CreateResourceFromFile(Macro, FirebaseNotifications.FirebaseNotifications)
'**************************************

' Added for location services
' This is removed as ir appears to causes uploading to google pay site "running bundletool build-apks on your uploaded App Bundle".
'   See post for more details https://www.b4x.com/android/forum/threads/error-found-multiple-meta-data-elements-for-key-com-google-android-gms-version-expected-at-most-one.144679/#content
'AddApplicationText(<meta-data
'   android:name="com.google.android.gms.version"
'  android:value="@integer/google_play_services_version" />)

AddPermission(android.permission.ACCESS_FINE_LOCATION)

' Added for non-https communications see https://www.b4x.com/android/forum/threads/android-jar-targetsdkversion-minsdkversion.87610/#content
' Don't appear to work.
' CreateResourceFromFile(Macro, Core.NetworkClearText)

' Suggested by Erel to avoid having to say yes to Advertising ID
'  See https://www.b4x.com/android/forum/threads/does-your-app-use-advertising-id.149736/
RemovePermission(com.google.android.gms.permission.AD_ID)

As I said this all worked up to a few hours ago.

Kind regards
Dave Morris
 

DonManfred

Expert
Licensed User
Longtime User
To request Permission you have to use Runtimeppermissions.

 
Upvote 0

davemorris

Active Member
Licensed User
Longtime User
Hi DonManfred

Thanks for the input. Fortunately, I have already implemented the requirements for the Runtimepermissions in code but it dates back to 2019. However, the basic mistake was I removed the code handling run time permissions by accident.

However, re-reading through release notes it a good thing as refreshes your knowledge and in this case helped me go straight to a fix for the problem.

Thanks again
Dave
p.s. I have made a small donation for your help.
 
Upvote 0
Top