innoveit / react-native-ble-manager

React Native BLE communication module
http://innoveit.github.io/react-native-ble-manager/
Apache License 2.0
2.09k stars 756 forks source link

support Android 13 / SDK 33 BLE library updates #943

Open matgardon opened 1 year ago

matgardon commented 1 year ago

Hi, as you may be aware, android 13 partially switched it's BLE stack to Gabeldorsche this summer. This change mainly impacts Advertising & Scanning for now.

As a consequence, several methods used are now flagged as deprecated, and some FLAGS have been added (for example in scan results error cases).

changes can be found here:

I think it would be wise to switch to the non-deprecated methods when possible (ie. on Android >=13) because some of those deprecated methods had race conditions / thread safety issues as discussed here. It could also be a complementary fix to the recently merged PR #935.

A good summary of the changes needed might be found in the Nordic lib in the following 2 PRs (both included in latest release, 2.6.0) :

I don't have much time right now but if I can help on that integration, I will.

Also, not directly related, but be aware that the new android 13 scan introduced issues which consequences I'm not yet 100% certain of, but they include:

roysG commented 1 year ago

Hi, I see that there is no any updates in the repository. how should i get the new fix?

marcosinigaglia commented 1 year ago

The library is working also on Android 13

askkerr commented 1 year ago

I'm not sure that it is. Android 13, Samsung Galaxy S21 Ultra. No peripherals added during scan

Edit: Location permissions issue. Disregard

matgardon commented 1 year ago

It is working, this issue is about supporting new non-deprecated methods for certain inner workings as explained in the issue desc. This is not (yet) a blocking issue. If you have issues with scan, there are probably a whole lot of reasons why, and they are probably not related to this library as scanning conditions may be tricky when first putting your hands into BLE on android.

MuhammadFaisal215 commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

askkerr commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

Make sure in your manifest you have uses-feature android.hardware.bluetooth_le required="true" android.permission.BLUETOOTH_SCAN "neverForLocation" android.permission.BLUETOOTH_ADMIN android.permission.BLUETOOTH_CONNECT android.permission.ACCESS_FINE_LOCATION

With the "neverforlocation" tag on the BLUETOOTH_SCAN permission, it will allow BLE scanning without needing location permissions. Do keep in mind even if permissions are granted, the respective adapters must be on for the scan to work.

MuhammadFaisal215 commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

Make sure in your manifest you have uses-feature android.hardware.bluetooth_le required="true" android.permission.BLUETOOTH_SCAN "neverForLocation" android.permission.BLUETOOTH_ADMIN android.permission.BLUETOOTH_CONNECT android.permission.ACCESS_FINE_LOCATION

With the "neverforlocation" tag on the BLUETOOTH_SCAN permission, it will allow BLE scanning without needing location permissions. Do keep in mind even if permissions are granted, the respective adapters must be on for the scan to work.

Thanks @askkerr. I have already added the permissions in manifest file that you have listed. And also I have granted all the permissions. My adapters are on. But still getting same issue. Not scanning BLE devices, but scanning other bluetooth devices.

askkerr commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

Make sure in your manifest you have uses-feature android.hardware.bluetooth_le required="true" android.permission.BLUETOOTH_SCAN "neverForLocation" android.permission.BLUETOOTH_ADMIN android.permission.BLUETOOTH_CONNECT android.permission.ACCESS_FINE_LOCATION

With the "neverforlocation" tag on the BLUETOOTH_SCAN permission, it will allow BLE scanning without needing location permissions. Do keep in mind even if permissions are granted, the respective adapters must be on for the scan to work.

Thanks @askkerr. I have already added the permissions in manifest file that you have listed. And also I have granted all the permissions. My adapters are on. But still getting same issue. Not scanning BLE devices, but scanning other bluetooth devices.

I'd love to help, but I'm not really even sure how you are finding classic devices. This library should only be for BLE.

askkerr commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

Make sure in your manifest you have uses-feature android.hardware.bluetooth_le required="true" android.permission.BLUETOOTH_SCAN "neverForLocation" android.permission.BLUETOOTH_ADMIN android.permission.BLUETOOTH_CONNECT android.permission.ACCESS_FINE_LOCATION With the "neverforlocation" tag on the BLUETOOTH_SCAN permission, it will allow BLE scanning without needing location permissions. Do keep in mind even if permissions are granted, the respective adapters must be on for the scan to work.

Thanks @askkerr. I have already added the permissions in manifest file that you have listed. And also I have granted all the permissions. My adapters are on. But still getting same issue. Not scanning BLE devices, but scanning other bluetooth devices.

@MuhammadFaisal215 just a thought, but are you specifying the service UUIDs of the devices you plan to be searching for? In my experience Android 13 on a Samsung S21 Ultra did not care if I specified service UUIDs, but we had issues on iOS if we didn't specify any UUIDs. Maybe it is a similar case with different hardware?

C0zmaCatalin commented 9 months ago

Hi, I am facing the same issue. When i use my App in android 11 it works fine and scan all nearby bluetooth devices, including classical and BLE devices. But when i use my App with android 12, 13, and 14, my app only scans classical bluetooth devices like, headphone, mobiles, smart watches, but not my BLE devices. I have requested and granted all type of permissions required regarding bluetooth and location, but didn't work. Can anyone help me on this. Thanks.

Same for me... I couldn't find any solution to fix this :(

Aladin-83 commented 8 months ago

Good morning, Being stuck on the same problem, after a few hours of testing and research, I found the solution! It is imperative to put


`<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
         android:usesPermissionFlags="neverForLocation" >

  in the manifest and check the authorizations in the program:

if (Platform.OS === 'android' && Platform.Version >= 23) {
             console.log('In verifyBluetoothAuthorization...',
                             Platform.Version)
             PermissionsAndroid.requestMultiple([
                 PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN,
                 PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT,
                 PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,

               ]).then(result => {

                 if (
                   (result['android.permission.BLUETOOTH_SCAN'] &&
                   result['android.permission.BLUETOOTH_CONNECT'] &&
                   result['android.permission.ACCESS_FINE_LOCATION'] === 'granted')
                   ||
                   (result['android.permission.BLUETOOTH_SCAN'] &&
                   result['android.permission.BLUETOOTH_CONNECT'] &&
                   result['android.permission.ACCESS_FINE_LOCATION'] === 'never_ask_again')
                 ) {
                   console.log('User accepted');
                   ActiveBluetoothInDevice()
                 } else {
                   console.log('User refused'); }
               });
           } ```

and suddenly everything works!
Aladin-83 commented 6 months ago

Bonjour,

Ravi pour vous !

Cordialement

P. Nolin

De : usama-tariq-qbatch @.> Envoyé : jeudi 29 février 2024 10:35 À : innoveit/react-native-ble-manager @.> Cc : Aladin-83 @.>; Mention @.> Objet : Re: [innoveit/react-native-ble-manager] support Android 13 / SDK 33 BLE library updates (Issue #943)

Good morning, Being stuck on the same problem, after a few hours of testing and research, I found the solution! It is imperative to put

`<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" >

in the manifest and check the authorizations in the program:

if (Platform.OS === 'android' && Platform.Version >= 23) { console.log('In verifyBluetoothAuthorization...', Platform.Version) PermissionsAndroid.requestMultiple([ PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN, PermissionsAndroid.PERMISSIONS.BLUETOOTH_CONNECT, PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,

           ]).then(result => {

             if (
               (result['android.permission.BLUETOOTH_SCAN'] &&
               result['android.permission.BLUETOOTH_CONNECT'] &&
               result['android.permission.ACCESS_FINE_LOCATION'] === 'granted')
               ||
               (result['android.permission.BLUETOOTH_SCAN'] &&
               result['android.permission.BLUETOOTH_CONNECT'] &&
               result['android.permission.ACCESS_FINE_LOCATION'] === 'never_ask_again')
             ) {
               console.log('User accepted');
               ActiveBluetoothInDevice()
             } else {
               console.log('User refused'); }
           });
       } ```

and suddenly everything works!

Thanks alot @Aladin-83 https://github.com/Aladin-83 I was searching for the fix for a long time, and your solution worked magically.

— Reply to this email directly, view it on GitHub https://github.com/innoveit/react-native-ble-manager/issues/943#issuecomment-1970748165 , or unsubscribe https://github.com/notifications/unsubscribe-auth/AL3UDWUM3EFSGLCMMVM67T3YV322NAVCNFSM6AAAAAAT437EI6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSNZQG42DQMJWGU . You are receiving this because you were mentioned. https://github.com/notifications/beacon/AL3UDWXFZHK22YCKXN5I7JDYV322NA5CNFSM6AAAAAAT437EI6WGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTTVO45QK.gif Message ID: @.***>