Hello Dear All,
I have read the articles about Bluetooth + Google API 31 and I tried to do it accordingly, but there is something I failed to solve. What I want to do:
- When start my app, ask for necessary Bluetooth permissions.
- If the user grants (or already granted) them, check if BT is enabled and if not, enable BT using an Activitystarter
- Let the user select the Bluetooth server to connect to
Please see the attached .aia. Test cases:
- If no permission given yet, the application starts and immediately drops a runtime error and ends (I attached the screenshot) but also asks for the Bluetooth (close devices) permission. If the user gives the permission, next time the application runs nicely (see step 2)
- If the permissions were granted, if BT is enabled, then you can immediately see the servers in the list. If the BT is not enabled, then the app asks for enabling BT then also runs nicely.
Of course I know why the runtime error happens. In the Scree.Initialize() function I start asking the BT permissions but immediately after I try to enable Bluetooth which is not going to happen if there are no permissions. However, I simply cannot check if the permissions were given or not.
I was thinking at first that I only need to ask for permission and if the permission was given or the user just gave it, then I was going to go to the Screen.PermissionGranted() but it's not the case. I only get to Screen.PermissionGranted() if the user just gave the permission. That is why the app drops the runtime error and asks for the permission at the same time.
The question is, how can I do it nicely? I want to enable Bluetooth if not enabled, BUT only in that case when the permissions are ready (otherwise I'd like to drop an error message to the user that without the permissions we cannot continue. I believe it's possible if I test in Screen.ErrorOccured() for ErrorNumber 908 or 517 or 506).
I have tested with Samsung Galaxy s10E Android v12 (last update 01/12/2022), One UI version 4.1
Could you please help, maybe?
BT_test_copy.aia (4.5 KB)