I am using altbeacon library with verison("2.19.4") for getting the estimoate beacons. Doing some R&D and getting the
m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24
above layout to set on Beacon parser class. I put this code on Beacon parser class and assign to beacon manager.
val beaconManager = BeaconManager.getInstanceForApplication(this)
beaconManager.beaconParsers.clear()
val parser = BeaconParser().setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24")
beaconManager.beaconParsers.add(parser)
val region = Region("com.beacon", null, null, null)
// Set up a Live Data observer so this Activity can get monitoring callbacks
// observer will be called each time the monitored regionState changes (inside vs. outside region)
beaconManager.getRegionViewModel(region).rangedBeacons.observe(this, rangingMonitorObserver)s
beaconManager.startRangingBeacons(region)
private val rangingMonitorObserver = Observer<Collection<Beacon>> { beacons ->
Log.d("HomeFragment TAG", "Ranged: ${beacons.count()} beacons")
for (beacon: Beacon in beacons) {
Log.d("HomeFragment TAG", "$beacon about ${beacon.distance} meters away")
}
}
I execute this code but did not get the beacons. Does Anyone Know How to get the estimote beacon using the alt beacon library?
Thanks in advance
There are lots of possible causes of failed beacon detections. One of the most common causes is if your app doesn't have the proper permissions from Android for Bluetooth scanning. The specific permissions needed vary depending on the
targetSdkVersionsetting in your build.gradle file:Note that most of the above permissions (other than ones suffixed with "install time") are runtime permissions which require writing code to prompt the user to grant them. If the user fails to grant them, or the permission are later lost or reverted, the scans won't work.
In addition to the above, if you want to detect beacons when the app is in the background (no activity visible on the screen) you must also have ACCESS_BACKGROUND_LOCATION permission on Android 10+ (targetSdkVersion 29 or higher).
Writing code to obtain these permissions can be tricky. The easiest way to confirm you have obtained them is to go to Settings -> Apps -> Your app name -> Permissions
Be aware that the names in the permissions screen are slightly different than the declared permissions in the manifest as shown in this screenshot:
Read my blog post here for more info on how we got here.