i have an application to scan BLE beacons around. I've used Altbeacon library to do that. When i run it on my Nexus 6p it finds some beacons but when i run it on galaxy s9 or Kindle fire HD 8 number of beacons it found is always zero. Here is my code:
override fun onBeaconServiceConnect() {
beaconManager.removeAllRangeNotifiers()
beaconManager.addRangeNotifier(object : RangeNotifier {
override fun didRangeBeaconsInRegion(beacons: Collection<Beacon>, region: Region) {
Log.i("ranging" , "beacons size:" + beacons.size)
for (b in beacons) {
Toast.makeText(getApplicationContext(),b.id1.toString() + " beacon I see is about " + b.rssi + " away.",
Toast.LENGTH_SHORT).show();
}
}
})
try {
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", Identifier.parse(""), null, null))
} catch (e: RemoteException) {
}
}
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val binding : com.example.attendancecheck_v1.databinding.FragmentTeacherScanningBinding = DataBindingUtil.inflate(
inflater, R.layout.fragment_teacher_scanning, container, false)
beaconManager.bind(this)
setHasOptionsMenu(true)
return binding.root
}
By the way, I installed a beacons simulator on my devices and it can scan for beacons but in my code, the output is zero on those devices.
check it with this region:
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", null, null, null))