Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No prompt for ACCESS_COARSE_LOCATION & ACCESS_FINE_LOCATION permissions #196

Open
MarkusMiller opened this issue Apr 18, 2024 · 7 comments

Comments

@MarkusMiller
Copy link

MarkusMiller commented Apr 18, 2024

Hello,

last year, I wrote a data-gathering app that takes images at fixed time intervals and gathers additional data from all sorts of APIs and sensors, such as GPS location.

This year, I tried to add a wind sensor that is connected via Bluetooth and I finally managed to write a sandbox app, that successfully transferred data between the Bluetooth anemometer and the app using blessed-android.

I then tried to merge the old app with the new Bluetooth functionality but as it turns out, the GPS sensor doesn't work anymore due to missing permission. The Android system is not showing any prompt to grant ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION and I spent a happy week watching sanity check after sanity check fail. Yesterday and today I started all over integrating part after part and as soon as I added

implementation("com.github.weliem:blessed-kotlin:3.0.6")

to the gradle script, the permission prompt for GPS location stopped appearing when launching the app. Removing the line restored the behaviour.

Checking the Permissions in the App-Info also changed the required "Location" permission into "Devices nearby" and back, which unfortunately doesn't help with GPS.

Unfortunately, I didn't find any documentation regarding the usage of the library along with GPS sensors. Is there any information on how to get both things working side by side, or is it maybe a bug?

Kind regards and thank you

@jones139
Copy link

I had a lot of trouble with something similar a couple of weeks ago. My issue was changes in the Bluetooth permissions between android 12 and android 13 (or maybe it was 11 and 12). If your list of permissions us incorrect, it does not show the dialog to request permissions, and fails quietly (I think this is an android bug but don't know where to report it).
Could including the library change your target or minimum sdk and therefore expose this issue for you?

@weliem
Copy link
Owner

weliem commented Apr 18, 2024

In later versions of Android, the location permissions are not needed anymore as they were replaced by dedicated BLE permissions. So if you need it for GPS functionality, you'll have to ask for them separately.

@MarkusMiller
Copy link
Author

MarkusMiller commented Apr 18, 2024

Hello, thank you for getting back.

@jones139 That were the permissions I actually tried to get (plus a couple of others) and the permissions for GPS were not granted. I just did a sanity check only granting the permissions you specified (line 102) and Android asked for permissions for all devices nearby but ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION weren't granted.

@weliem I did a sanity check, only asking for ACCESS_COARSE_LOCATION and ACCESS_FINE_LOCATION, which worked perfectly fine, but as soon as I added the implementation-call above, Android stopped showing the grant permission prompt. With added GPS functions, those functions just stopped working as soon as I added the library, due to lacking permissions :-/

Any resource I could find on that topic told me to ask for COARSE/FINE permission but what am I supposed to do if I can't grant the permissions anymore, as soon as I add the implementation line?

I checked again: If I ask for ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION, BLUETOOTH_SCAN, BLUETOOTH_CONNECT, and BLUETOOTH_ADVERTISE permissions, everything is fine until I add implementation("com.github.weliem:blessed-kotlin:3.0.6") to the gradle file. I don't know, what's going on.

@MarkusMiller
Copy link
Author

I'm not entirely sure, yet, but I think I might have found the issue:

In https://github.com/weliem/blessed-kotlin/blob/main/blessed/src/main/AndroidManifest.xml

<uses-permission
        android:name="android.permission.ACCESS_FINE_LOCATION"
        android:maxSdkVersion="30" />
<uses-permission
        android:name="android.permission.ACCESS_COARSE_LOCATION"
        android:maxSdkVersion="30" />

declare the permissions in question up to SDK version 30. I'm using version 33 as that's the version of my phone and as I just learned from a side note, Android merges manifests. So, by declaring the permissions in my manifest, the "missing" android:maxSdkVersion most likely got merged into my app's manifest once I added the implementation line.

So, I added

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
        tools:node="remove"
        tools:selector="com.welie.blessed"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"
        tools:node="remove"
        tools:selector="com.welie.blessed"/>

into my manifest in the hopes that this would not merge the library's manifest into my app and as I just tested now, I'm getting asked by the system to grant location permissions and devices nearby permissions.

Not sure yet, if it actually works, but let's see...

@weliem
Copy link
Owner

weliem commented Apr 21, 2024

Yes, I think that should work!

@MarkusMiller
Copy link
Author

It's working, yes. Confirmed. I think this ticket can be closed now and the workaround for newer API versions could be included in the documentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants