I'm trying to figure out the maze of permissions r...
# compose
t
I'm trying to figure out the maze of permissions requesting for BLEScanning, but in a Compose app. I'm struggling with how to architect this. When I press my "scan" button, should I make that fire a method on my Activity? or my ViewModel? Is the dance one does to check/request permissions done the same as it always has been? or are their newer composey ways to do that part?
m
This worked well for me, https://github.com/google/accompanist/tree/main/permissions But I was not doing anything complicated.
t
I just got build.gradle error when I added their two suggested lines in there
m
Looks like that is groovy based. But just add it like you would any other third party library, such as compose itself.
t
I got the basic example there working, twisted around for BLUETOOTH_SCAN instead of CAMERA. It seems weird to me from a user flow to have the permission inlined like this. For discoverability, I (think) I want a button always just labeled "SCAN". In BLE parlance, that's pretty clear. And if the user stabs it, then I guess I expect the classic intervention modal (we need to chat before you can proceed).
(thanks for the help and hints btw)
s
are you squared away? We’ve implemented BLE scanning in our app. The permissions need some TLC though. Between the phone level BT permission, and the app level “Nearby Devices” perm, you gotta be careful the order that you ask them in, and be prepared for one/both/either to be enabled/disabled when your app launches. I’ve got to fix a crash where the nearby devices perm intent crashes the app cause it needs the phone level BT perm first.
This is the library we’re using: https://github.com/weliem/blessed-android-coroutines
t
Actually, my whole reason for doing this is... We use the Nordic scanner library. But with recent SDK changes, we've had a hard time keeping the permissions straight. We regressed our BLE ability in a recent push we did on some devices. So I thought I'd sit back and just right a simple app that did just the scanning part (separated from the complexity of the rest of our app). And then I did a foolish thing. I thought "since I'm sort of 'going back to ground 0' with this", I'll try and tackle it with this new fangled Compose stuff. I've mostly done work on the iOS side for this app pair, but recently have needed to take a more involved role in the Android variant. So I'm not a super strong architect in any of the variuous Android methodologies over the years
s
is the simple app Compose-only, single-activity?
👌 1
m
I wouldn't create a button just for enabling the permission. I would keep the single scan button and change what it means if they have the permission on or off.
s
@Scott Peterson Thanks for mentioning that. I wish I'd seen that 2 months ago. I wrote some simple wrappers for my specific use, but this looks much nicer.
When looking more into BLESSED, I found KABLE. It's quite nice and they have a nice demo here: https://github.com/JuulLabs/sensortag
I wrote a simple app to use a SecuGen fingerprint reader. If you're interested in seeing my much more disgusting code, you can find that here: https://github.com/sproctor/fingerprint-example/tree/kable