react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

Need a restart for scanning peripherals

Open GalliusJulius opened this issue 3 years ago • 11 comments

Hello

Version

  • react-native-ble-manager v7.4.1
  • react-native v0.63.4
  • iOS/Android v. 10 QKQ1.190825.002

Expected behaviour

Peripherals should appear after scanning (same behaviour with my app or the example)

Actual behaviour

Peripherals are only appear once the app is installed on the phone (with react-native run-android) and I restart my phone.

Steps to reproduce

  1. react-native run-android (in the example folder) => running on a android phone throw USB.

Stack trace and console log

It's entering in the .then of the scan method (Scanning is log in the console). I don't see other logs that could be useful (don't hesitate to ask for some if needed)

The workaround works fine for dev but I hope I will not have the same issue in prod.

In advance thank you.

GalliusJulius avatar Dec 13 '20 16:12 GalliusJulius

Can you provide a sample of what you're doing? The scan only runs of the specified period of time, and that's it. If you want to scan again (or scan continuously), you need to run another scan. Note that running the scan again will clear out the discovered peripherals, so if you want a running list of all peripherals, you'll need to maintain that state separately.

If you are just having trouble knowing when you have peripherals, you can use the BleManagerDiscoverPeripheral event (called everytime an advertisement is seen), or you can periodically call getDiscoveredPeripherals

rfestag avatar Dec 30 '20 17:12 rfestag

I have this issue with the example provide in the react-native-ble-menager repository. The issue here is that BleManagerDiscoverPeripheral event isn't triggered even with peripherals available close to my phone. I don't think the issue come from my phone as I can see BLE devices with other applications (nerf connect for instance).

GalliusJulius avatar Jan 01 '21 17:01 GalliusJulius

I am also having this issue with Android (10). I have to disable then reenable location permissions in able to start discovering peripherals.

react-native-ble-manager 7.3.1

iAmHarmon avatar Jan 26 '21 00:01 iAmHarmon

I still didn't find a solution but I guess I know where it's coming from : The location permission pop-up only asks if I want to use location only when the app is running or never but not the third option : always. When I go to the settings of my app I can switch this permission from only when the app is running to always and it's working fine.

So lot of questions :

  • Why do I not have the always allowed proposition on my app?
  • Is there an issue with the state handle of the application in the example (in my case)?
  • Why is it not working with the only allowed when running?

@iAmHarmon can you confirm this (not having the possibility to always allow localization in the user pop-up)?

BTW in the meantime, I updated to 7.4.1, I'm editing the first message

GalliusJulius avatar Jan 26 '21 10:01 GalliusJulius

I'll take a stab:

  1. Does adding the BACKGROUND_LOCATION cause "always" to show up - https://stackoverflow.com/questions/61909313/allow-all-the-time-location-prompt-not-coming-in-android-sdk-29
  2. I'm curious if you need to re-request the permission after you resume if you don't have the background permission?

rfestag avatar Jan 26 '21 11:01 rfestag

I'll take a stab:

  1. Does adding the BACKGROUND_LOCATION cause "always" to show up - https://stackoverflow.com/questions/61909313/allow-all-the-time-location-prompt-not-coming-in-android-sdk-29
  2. I'm curious if you need to re-request the permission after you resume if you don't have the background permission?

At first I also thought it was that, But I already have <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/> in my manifest

GalliusJulius avatar Jan 26 '21 16:01 GalliusJulius

@GalliusJulius , did you get it working ?

franzejr avatar May 02 '21 23:05 franzejr

Could it be because requesting ACCESS_BACKGROUND_LOCATION permission needs to be handled differently on different Android versions?

This could help: https://medium.com/swlh/request-location-permission-correctly-in-android-11-61afe95a11ad

zhifeng-heng avatar Jul 08 '21 06:07 zhifeng-heng

I am having this issue as well, any updates?

Rowansdabomb avatar Aug 20 '21 22:08 Rowansdabomb

Hi, having the same issue

rUCUS avatar Dec 21 '21 16:12 rUCUS

i have this issue as well !!!

bassamyan avatar Dec 22 '21 03:12 bassamyan