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
}
通过在我的设备上安装信标模拟器的方式,它可以扫描信标,但是在我的代码中,这些设备上的输出为零
答案 0 :(得分:0)
在此区域进行检查:
beaconManager.startRangingBeaconsInRegion(Region("myRangingUniqueId", null, null, null))