Driversnote-Dev / react-native-kontaktio

React Native (iOS and Android) library for Kontakt.io beacons (and all other beacons)
MIT License
112 stars 48 forks source link

Not working on Android 10 [Solved] #78

Closed monickaalexander closed 1 year ago

monickaalexander commented 3 years ago

I tried to implement the minimal code on Android 10 device. I seems that the device is not able to add listeners as the DeviceEventEmitter.addlistener() is not working.

if(isAndroid) {
      console.log('enter listener')
      DeviceEventEmitter.addListener('beaconsDidUpdate', ({beacons, region}) => {
        console.log('checking places')
        for (i = 0; i < beacons.length; i++) {
          console.log('Beacons detected [major, rssi, uuid]---->', beacons[i].major, beacons[i].rssi, beacons[i].uuid);
      }});
  } 
else {
      kontaktEmitter.addListener('didRangeBeacons', ({beacons, region}) => {
        console.log('BeaconsinRange: ', beacons.length);
        for (i = 0; i < beacons.length; i++) {
          console.log('Beacons detected [major, rssi, uuid]---->', beacons[i].major, beacons[i].rssi, beacons[i].uuid);
        }
      });
  }
};

Is there any set up that needs to be done I am missing on? Thanks

AkaashK commented 3 years ago

Facing same issue, any solution to this

YCMitch commented 3 years ago

+1 - doesn't work on Android 10 or 11...

hl2000 commented 3 years ago

Hello guys, As Android 10 has introduced the new requirement of permission, please request "ACCESS_FINE_LOCATION" instead of the "ACCESS_COARSE_LOCATION" in your code. I just made this change and it works on Android 10 and 11 devices again.

don't forget to add \<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> into ApplicationManifest.xml file

Ref: https://altbeacon.github.io/android-beacon-library/requesting_permission.html

YCMitch commented 3 years ago

I already have ACCESS_FINE_LOCATION (and ACCESS_COARSE_LOCATION) in there, and it still doesn't work for Android 10/11. Do you think removing ACCESS_COARSE_LOCATION would help? Does yours have that too?

hl2000 commented 3 years ago

In the latest Minimal Example(maybe updated since last year), I have replaced the "PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION" with "PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION", and it starts to work on Android 10 and 11 devices.

By the way, do you have \<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> in your ApplicationManifest.xml file?

YCMitch commented 3 years ago

Yeah, that's already in there. I'll try removing ACCESS_COARSE_LOCATION perhaps, and see if it helps.

andrekovac commented 3 years ago

Thanks @hl2000 for sharing this! Would you mind updating the Android docs and the Minimal Example to reflect this new requirement for Android 10+?